diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index caea833027e..978afa296e9 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -718,6 +718,12 @@ void AsmConstWalker::visitCall(Call* curr) { if (set) { assert(set->index == get->index); arg = set->value; + } else { + Fatal() << "local.get of unknown in arg0 of call to " << import->base + << " (used by EM_ASM* macros) in function " + << getFunction()->name + << ".\nThis might be caused by aggressive compiler " + "transformations. Consider using EM_JS instead."; } } else if (auto* value = arg->dynCast()) { // In the dynamic linking case the address of the string constant @@ -729,7 +735,7 @@ void AsmConstWalker::visitCall(Call* curr) { } else { if (!value) { Fatal() << "Unexpected arg0 type (" << getExpressionName(arg) - << ") in call to to: " << import->base; + << ") in call to: " << import->base; } } } diff --git a/test/unit/input/em_asm_mangled_string.wast b/test/unit/input/em_asm_mangled_string.wast new file mode 100644 index 00000000000..aa856270d96 --- /dev/null +++ b/test/unit/input/em_asm_mangled_string.wast @@ -0,0 +1,11 @@ +(module + (import "env" "emscripten_asm_const_int" (func $emscripten_asm_const_int (param i32 i32 i32) (result i32))) + (global $global$0 (mut i32) (i32.const 66192)) + (global $global$1 i32 (i32.const 652)) + (export "__data_end" (global $global$1)) + (export "main" (func $main)) + (func $main (param $0 i32) (param $1 i32) (result i32) + (drop (call $emscripten_asm_const_int (local.get $0) (i32.const 0) (i32.const 0))) + (i32.const 0) + ) +) diff --git a/test/unit/test_finalize.py b/test/unit/test_finalize.py new file mode 100644 index 00000000000..cdcfe27e809 --- /dev/null +++ b/test/unit/test_finalize.py @@ -0,0 +1,14 @@ +from scripts.test.shared import WASM_EMSCRIPTEN_FINALIZE, run_process +from .utils import BinaryenTestCase +import os + + +class EmscriptenFinalizeTest(BinaryenTestCase): + def test_em_asm_mangled_string(self): + input_dir = os.path.dirname(__file__) + p = run_process(WASM_EMSCRIPTEN_FINALIZE + [ + os.path.join(input_dir, 'input', 'em_asm_mangled_string.wast'), '-o', os.devnull, '--global-base=1024' + ], check=False, capture_output=True) + self.assertNotEqual(p.returncode, 0) + self.assertIn('Fatal: local.get of unknown in arg0 of call to $emscripten_asm_const_int (used by EM_ASM* macros) in function $main.', p.stderr) + self.assertIn('This might be caused by aggressive compiler transformations. Consider using EM_JS instead.', p.stderr)