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..d5b5c82caee9c0b990ba2f5bb3bff5ed8c7a0d5b 100644 |
--- a/test/cctest/wasm/test-run-wasm.cc |
+++ b/test/cctest/wasm/test-run-wasm.cc |
@@ -2632,6 +2632,49 @@ 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); |
+ |
+ WasmFunctionCompiler t3(sigs.f_ff(), &module); |
+ BUILD(t3, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ t3.CompileAndAdd(/*sig_index*/ 2); |
+ |
+ // Signature table. |
+ module.AddSignature(sigs.i_ii()); |
+ module.AddSignature(sigs.i_ii()); |
+ module.AddSignature(sigs.f_ff()); |
+ |
+ // Function table. |
+ uint16_t i1 = static_cast<uint16_t>(t1.function_index()); |
+ uint16_t i2 = static_cast<uint16_t>(t2.function_index()); |
+ uint16_t i3 = static_cast<uint16_t>(t3.function_index()); |
+ uint16_t indirect_function_table[] = {i1, i2, i3, i1, i2}; |
+ |
+ 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_TRAP(r.Call(2)); |
+ CHECK_EQ(88, r.Call(3)); |
+ CHECK_EQ(66, r.Call(4)); |
+ CHECK_TRAP(r.Call(5)); |
+} |
+ |
WASM_EXEC_TEST(F32Floor) { |
WasmRunner<float> r(execution_mode, MachineType::Float32()); |
BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |