From 9bfade13c4cd5ebce7ae70681c655302f0f02ce7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jul 2020 18:25:56 -0700 Subject: 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. --- test/wasm2js/ordering.2asm.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/wasm2js/ordering.2asm.js') diff --git a/test/wasm2js/ordering.2asm.js b/test/wasm2js/ordering.2asm.js index 1fbfd0c03..f3d879a99 100644 --- a/test/wasm2js/ordering.2asm.js +++ b/test/wasm2js/ordering.2asm.js @@ -23,10 +23,10 @@ function asmFunc(global, env, buffer) { var infinity = global.Infinity; function main() { var wasm2js_i32$0 = 0, wasm2js_i32$1 = 0, wasm2js_i32$2 = 0; - FUNCTION_TABLE[foo(2 | 0) | 0](1) | 0; - FUNCTION_TABLE[4](foo(3 | 0) | 0) | 0; - (wasm2js_i32$1 = foo(5 | 0) | 0, wasm2js_i32$0 = bar(6 | 0) | 0), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0; - FUNCTION_TABLE[8](7) | 0; + FUNCTION_TABLE[foo(2 | 0) | 0 | 0](1) | 0; + FUNCTION_TABLE[4 | 0](foo(3 | 0) | 0) | 0; + (wasm2js_i32$1 = foo(5 | 0) | 0, wasm2js_i32$0 = bar(6 | 0) | 0 | 0), FUNCTION_TABLE[wasm2js_i32$0](wasm2js_i32$1 | 0) | 0; + FUNCTION_TABLE[8 | 0](7) | 0; baz((11 ? 9 : 10) | 0) | 0; baz((wasm2js_i32$0 = foo(12 | 0) | 0, wasm2js_i32$1 = 13, wasm2js_i32$2 = 14, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1) | 0) | 0; baz((wasm2js_i32$0 = 15, wasm2js_i32$1 = foo(16 | 0) | 0, wasm2js_i32$2 = 17, wasm2js_i32$2 ? wasm2js_i32$0 : wasm2js_i32$1) | 0) | 0; -- cgit v1.2.3