Commit 85cb43cb authored by titzer's avatar titzer Committed by Commit bot

[wasm] Fix canonicalization bug for function signatures in CallIndirect.

R=ahaas@chromium.org
BUG=chromium:654231

Review-Url: https://chromiumcodereview.appspot.com/2439613003
Cr-Commit-Position: refs/heads/master@{#40463}
parent 20d29ff0
...@@ -2176,10 +2176,11 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, Node*** rets, ...@@ -2176,10 +2176,11 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, Node*** rets,
Int32Constant(kPointerSizeLog2)), Int32Constant(kPointerSizeLog2)),
Int32Constant(fixed_offset)), Int32Constant(fixed_offset)),
*effect_, *control_); *effect_, *control_);
int32_t key = module_->module->function_tables[0].map.Find(sig); auto map = const_cast<wasm::SignatureMap&>(
DCHECK_GE(key, 0); module_->module->function_tables[0].map);
Node* sig_match = graph()->NewNode(machine->WordEqual(), load_sig, Node* sig_match = graph()->NewNode(
jsgraph()->SmiConstant(key)); machine->WordEqual(), load_sig,
jsgraph()->SmiConstant(static_cast<int>(map.FindOrInsert(sig))));
trap_->AddTrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position); trap_->AddTrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
} }
......
...@@ -2640,6 +2640,29 @@ WASM_EXEC_TEST(CallIndirect_NoTable) { ...@@ -2640,6 +2640,29 @@ WASM_EXEC_TEST(CallIndirect_NoTable) {
CHECK_TRAP(r.Call(2)); CHECK_TRAP(r.Call(2));
} }
WASM_EXEC_TEST(CallIndirect_EmptyTable) {
TestSignatures sigs;
TestingModule module(execution_mode);
// One function.
WasmFunctionCompiler t1(sigs.i_ii(), &module);
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd(/*sig_index*/ 1);
// Signature table.
module.AddSignature(sigs.f_ff());
module.AddSignature(sigs.i_ii());
module.AddIndirectFunctionTable(nullptr, 0);
// Builder the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22)));
CHECK_TRAP(r.Call(0));
CHECK_TRAP(r.Call(1));
CHECK_TRAP(r.Call(2));
}
WASM_EXEC_TEST(CallIndirect_canonical) { WASM_EXEC_TEST(CallIndirect_canonical) {
TestSignatures sigs; TestSignatures sigs;
TestingModule module(execution_mode); TestingModule module(execution_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment