diff options
author | Alon Zakai <azakai@google.com> | 2020-07-22 18:25:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 18:25:56 -0700 |
commit | 9bfade13c4cd5ebce7ae70681c655302f0f02ce7 (patch) | |
tree | 582fa6e0f14bf86839ed8c640e175bdff21af439 /test/wasm2js/indirect-select.2asm.js | |
parent | 3ac849384aa861382d2ca9636a89556e237e55d6 (diff) | |
download | binaryen-9bfade13c4cd5ebce7ae70681c655302f0f02ce7.tar.gz binaryen-9bfade13c4cd5ebce7ae70681c655302f0f02ce7.tar.bz2 binaryen-9bfade13c4cd5ebce7ae70681c655302f0f02ce7.zip |
wasm2js: coerce function pointer indexes (#2979)
We emit FUNCTION_TABLE[ptr], where FUNCTION_TABLE is a JS
array. That is a rare case where true is handled differently than 1
(a typed array or an add would cast, etc.), so we must explicitly cast
there.
Fixes an issue that existed before, but became a problem due to
#2869 which optimized some selects into a form that emitted a true
or a false, and if that was a function pointer, it could be bad, see
https://app.circleci.com/pipelines/github/emscripten-core/emscripten/6699/workflows/0c4da49c-75d0-4b0a-8fac-686a8330a3fe/jobs/336520
The new test/wasm2js/indirect-select.2asm.js.opt output shows
what happened there.
Verified as passing emscripten's wasm2js1 wasm2js2 test suites.
Diffstat (limited to 'test/wasm2js/indirect-select.2asm.js')
-rw-r--r-- | test/wasm2js/indirect-select.2asm.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/wasm2js/indirect-select.2asm.js b/test/wasm2js/indirect-select.2asm.js new file mode 100644 index 000000000..d190bb082 --- /dev/null +++ b/test/wasm2js/indirect-select.2asm.js @@ -0,0 +1,43 @@ +import { FUNCTION_TABLE } from 'env'; + +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(x) { + x = x | 0; + return FUNCTION_TABLE[(x ? 1 : 0) | 0]() | 0 | 0; + } + + function $1(x) { + x = x | 0; + return FUNCTION_TABLE[(x ? 0 : 1) | 0]() | 0 | 0; + } + + return { + "foo_true": $0, + "foo_false": $1 + }; +} + +var memasmFunc = new ArrayBuffer(65536); +var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc); +export var foo_true = retasmFunc.foo_true; +export var foo_false = retasmFunc.foo_false; |