Skip to content

Commit 86b8cf6

Browse files
authored
Fix infinite loop in AsmConstWalker::visitCall (#2303)
1 parent 42f98bc commit 86b8cf6

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/wasm/wasm-emscripten.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,12 @@ void AsmConstWalker::visitCall(Call* curr) {
718718
if (set) {
719719
assert(set->index == get->index);
720720
arg = set->value;
721+
} else {
722+
Fatal() << "local.get of unknown in arg0 of call to " << import->base
723+
<< " (used by EM_ASM* macros) in function "
724+
<< getFunction()->name
725+
<< ".\nThis might be caused by aggressive compiler "
726+
"transformations. Consider using EM_JS instead.";
721727
}
722728
} else if (auto* value = arg->dynCast<Binary>()) {
723729
// In the dynamic linking case the address of the string constant
@@ -729,7 +735,7 @@ void AsmConstWalker::visitCall(Call* curr) {
729735
} else {
730736
if (!value) {
731737
Fatal() << "Unexpected arg0 type (" << getExpressionName(arg)
732-
<< ") in call to to: " << import->base;
738+
<< ") in call to: " << import->base;
733739
}
734740
}
735741
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(module
2+
(import "env" "emscripten_asm_const_int" (func $emscripten_asm_const_int (param i32 i32 i32) (result i32)))
3+
(global $global$0 (mut i32) (i32.const 66192))
4+
(global $global$1 i32 (i32.const 652))
5+
(export "__data_end" (global $global$1))
6+
(export "main" (func $main))
7+
(func $main (param $0 i32) (param $1 i32) (result i32)
8+
(drop (call $emscripten_asm_const_int (local.get $0) (i32.const 0) (i32.const 0)))
9+
(i32.const 0)
10+
)
11+
)

test/unit/test_finalize.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from scripts.test.shared import WASM_EMSCRIPTEN_FINALIZE, run_process
2+
from .utils import BinaryenTestCase
3+
import os
4+
5+
6+
class EmscriptenFinalizeTest(BinaryenTestCase):
7+
def test_em_asm_mangled_string(self):
8+
input_dir = os.path.dirname(__file__)
9+
p = run_process(WASM_EMSCRIPTEN_FINALIZE + [
10+
os.path.join(input_dir, 'input', 'em_asm_mangled_string.wast'), '-o', os.devnull, '--global-base=1024'
11+
], check=False, capture_output=True)
12+
self.assertNotEqual(p.returncode, 0)
13+
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)
14+
self.assertIn('This might be caused by aggressive compiler transformations. Consider using EM_JS instead.', p.stderr)

0 commit comments

Comments
 (0)