Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2403093002: [wasm] Canonicalize function signature indices for matching in indirect calls. (Closed)
Patch Set: Add TODO for myself Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/wasm/test-run-wasm.cc
diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc
index d9d9db80e15e54a9cbe947d96ee9187b9ea82fea..109a47144fadc25c4051b897b72b0f3260af98bc 100644
--- a/test/cctest/wasm/test-run-wasm.cc
+++ b/test/cctest/wasm/test-run-wasm.cc
@@ -2632,6 +2632,39 @@ WASM_EXEC_TEST(CallIndirect_NoTable) {
CHECK_TRAP(r.Call(2));
}
+WASM_EXEC_TEST(CallIndirect_canonical) {
+ TestSignatures sigs;
+ TestingModule module(execution_mode);
+
+ WasmFunctionCompiler t1(sigs.i_ii(), &module);
+ BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ t1.CompileAndAdd(/*sig_index*/ 0);
+
+ WasmFunctionCompiler t2(sigs.i_ii(), &module);
+ BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ t2.CompileAndAdd(/*sig_index*/ 1);
+
+ // Signature table.
+ module.AddSignature(sigs.i_ii());
+ module.AddSignature(sigs.i_ii());
+
+ // Function table.
+ uint16_t indirect_function_table[] = {0, 1, 0, 1};
+ module.AddIndirectFunctionTable(indirect_function_table,
+ arraysize(indirect_function_table));
+ module.PopulateIndirectFunctionTable();
+
+ // Builder the caller function.
+ WasmRunner<int32_t> r(&module, MachineType::Int32());
+ BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11)));
+
+ CHECK_EQ(88, r.Call(0));
+ CHECK_EQ(66, r.Call(1));
+ CHECK_EQ(88, r.Call(2));
+ CHECK_EQ(66, r.Call(3));
+ CHECK_TRAP(r.Call(4));
+}
+
WASM_EXEC_TEST(F32Floor) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0)));

Powered by Google App Engine
This is Rietveld 408576698