Skip to content

Fix infinite loop in AsmConstWalker::visitCall #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/wasm/wasm-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Binary>()) {
// In the dynamic linking case the address of the string constant
Expand All @@ -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;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/input/em_asm_mangled_string.wast
Original file line number Diff line number Diff line change
@@ -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)
)
)
14 changes: 14 additions & 0 deletions test/unit/test_finalize.py
Original file line number Diff line number Diff line change
@@ -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)