diff options
author | Alon Zakai <azakai@google.com> | 2020-07-20 19:24:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 19:24:56 -0700 |
commit | 2e18aff8c9d4867d9c8e7db81948a672c028348f (patch) | |
tree | b8ef6b8ec097e8d2d5bcdc313c621b91728e26f8 /test/wasm2js/reinterpret_scratch.2asm.js.opt | |
parent | 4b60d34d807bf803cefee8fd16b9000bcfc1bdc7 (diff) | |
download | binaryen-2e18aff8c9d4867d9c8e7db81948a672c028348f.tar.gz binaryen-2e18aff8c9d4867d9c8e7db81948a672c028348f.tar.bz2 binaryen-2e18aff8c9d4867d9c8e7db81948a672c028348f.zip |
wasm2js: Fix a bug with adjacent reinterprets (#2964)
i64 reinterprets were lowered in the i64 pass, and i32s at the very end, in
wasm2js itself. This could break since in between the i64 pass and wasm2js
we run optimizations, and the optimizer was not aware of what we lower
the i32 reinterprets to - calls to use scratch memory. Those calls have a
side effect of altering scratch memory. The optimizer just saw an i32
reinterpret, and moved it across the i64 reinterpret's scratch memory calls.
This makes 32-bit reinterprets use separate scratch memory from 64-bit ones,
which means they can never interfere with each other.
Diffstat (limited to 'test/wasm2js/reinterpret_scratch.2asm.js.opt')
-rw-r--r-- | test/wasm2js/reinterpret_scratch.2asm.js.opt | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/wasm2js/reinterpret_scratch.2asm.js.opt b/test/wasm2js/reinterpret_scratch.2asm.js.opt new file mode 100644 index 000000000..03052fa92 --- /dev/null +++ b/test/wasm2js/reinterpret_scratch.2asm.js.opt @@ -0,0 +1,59 @@ + + + var scratchBuffer = new ArrayBuffer(16); + var i32ScratchView = new Int32Array(scratchBuffer); + var f32ScratchView = new Float32Array(scratchBuffer); + var f64ScratchView = new Float64Array(scratchBuffer); + + function wasm2js_scratch_load_i32(index) { + return i32ScratchView[index]; + } + + function wasm2js_scratch_store_f64(value) { + f64ScratchView[0] = value; + } + +function asmFunc(global, env, buffer) { + var HEAP8 = new global.Int8Array(buffer); + var HEAP16 = new global.Int16Array(buffer); + var HEAP32 = new global.Int32Array(buffer); + var HEAPU8 = new global.Uint8Array(buffer); + var HEAPU16 = new global.Uint16Array(buffer); + var HEAPU32 = new global.Uint32Array(buffer); + var HEAPF32 = new global.Float32Array(buffer); + var HEAPF64 = new global.Float64Array(buffer); + var Math_imul = global.Math.imul; + var Math_fround = global.Math.fround; + var Math_abs = global.Math.abs; + var Math_clz32 = global.Math.clz32; + var Math_min = global.Math.min; + var Math_max = global.Math.max; + var Math_floor = global.Math.floor; + var Math_ceil = global.Math.ceil; + var Math_sqrt = global.Math.sqrt; + var abort = env.abort; + var nan = global.NaN; + var infinity = global.Infinity; + function $0() { + var $0_1 = 0; + wasm2js_scratch_store_f64(305419896.0); + $0_1 = wasm2js_scratch_load_i32(1) | 0; + HEAP32[0] = wasm2js_scratch_load_i32(0); + HEAP32[1] = $0_1; + return HEAP32[0]; + } + + var FUNCTION_TABLE = []; + function __wasm_memory_size() { + return buffer.byteLength / 65536 | 0; + } + + return { + "foo": $0 + }; +} + +var memasmFunc = new ArrayBuffer(65536); +var bufferView = new Uint8Array(memasmFunc); +var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc); +export var foo = retasmFunc.foo; |