Skip to content

Commit 6754170

Browse files
committed
Fix some embind tests under >2gb addressing
This fixes a bug in `handleI64Signatures` which was using `receiveI64ParamAsI53` erroneously for incoming pointers under wasm32.
1 parent 2e25dd9 commit 6754170

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ jobs:
621621
wasm64_4gb.test_async_main
622622
wasm64_4gb.*embind*
623623
core_2gb.test_em_asm
624+
core_2gb.test_embind_unsigned_bigint
625+
core_2gb.test_embind_no_rtti
624626
wasm64l.test_bigswitch
625627
other.test_memory64_proxies
626628
other.test_failing_growth_wasm64"

src/jsifier.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ function runJSify() {
140140
error(`handleI64Signatures: missing name for argument ${i} in ${symbol}`);
141141
return snippet;
142142
}
143-
if (WASM_BIGINT) {
144-
if (sig[i] == 'p' || (sig[i] == 'j' && i53abi)) {
145-
argConvertions += ` ${receiveI64ParamAsI53(name, undefined, false)}\n`;
146-
}
143+
if (WASM_BIGINT && ((MEMORY64 && sig[i] == 'p') || (i53abi && sig[i] == 'j'))) {
144+
argConvertions += ` ${receiveI64ParamAsI53(name, undefined, false)}\n`;
147145
} else {
148146
if (sig[i] == 'j' && i53abi) {
149147
argConvertions += ` ${receiveI64ParamAsI53(name, undefined, false)}\n`;

src/library_int53.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ addToLibrary({
132132
// Returns NaN if the incoming bigint is outside the range.
133133
$bigintToI53Checked__deps: ['$MAX_INT53', '$MIN_INT53'],
134134
$bigintToI53Checked: (num) => {
135+
#if ASSERTIONS
136+
assert(typeof num == 'bigint', typeof num);
137+
#endif
135138
return (num < MIN_INT53 || num > MAX_INT53) ? NaN : Number(num);
136139
},
137140
#endif

src/parseTools.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ function getHeapOffset(offset, type) {
296296
const shifts = Math.log(sz) / Math.LN2;
297297
if (MEMORY64 == 1) {
298298
return `((${offset})/${2 ** shifts})`;
299+
} else if (CAN_ADDRESS_2GB) {
300+
return `((${offset})>>>${shifts})`;
299301
} else {
300302
return `((${offset})>>${shifts})`;
301303
}
@@ -422,7 +424,8 @@ function makeSetValueImpl(ptr, pos, value, type) {
422424

423425
function makeHEAPView(which, start, end) {
424426
const size = parseInt(which.replace('U', '').replace('F', '')) / 8;
425-
const mod = size == 1 ? '' : ('>>' + Math.log2(size));
427+
const shift = Math.log2(size);
428+
const mod = size == 1 ? '' : CAN_ADDRESS_2GB ? ('>>>' + shift) : ('>>' + shift);
426429
return `HEAP${which}.subarray((${start})${mod}, (${end})${mod})`;
427430
}
428431

tools/extract_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def extract_metadata(filename):
320320
if e.kind == webassembly.ExternType.GLOBAL and e.name.startswith('__em_js__'):
321321
name = utils.removeprefix(e.name, '__em_js__')
322322
globl = module.get_global(e.index)
323-
string_address = get_global_value(globl)
323+
string_address = to_unsigned(get_global_value(globl))
324324
em_js_funcs[name] = get_string_at(module, string_address)
325325

326326
for i in imports:

0 commit comments

Comments
 (0)