summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-02-03 14:41:37 -0800
committerGitHub <noreply@github.com>2020-02-03 14:41:37 -0800
commite0a449672a372aced4d11b4d60a49293d413a9bb (patch)
tree4b3879c08c8fbfddf38d8092bdac99c6ffb5f9a2 /test
parentc9f2e9b7b24182e830f39c176170d5ca64d3d05e (diff)
downloadbinaryen-e0a449672a372aced4d11b4d60a49293d413a9bb.tar.gz
binaryen-e0a449672a372aced4d11b4d60a49293d413a9bb.tar.bz2
binaryen-e0a449672a372aced4d11b4d60a49293d413a9bb.zip
Trap when call_indirect's signatures mismatch (#2636)
This makes the interpreter trap when the signature in `call_indirect` instruction and that of the actual function in the table mismatch. This also makes the `wasm-ctor-eval` not evaluate `call_indirect` in case the signatures mismatch. Before we only compared the arguments' signature and the function signature, which was sufficient before we had subtypes, but now the signature in `call_indirect` and that of the actual function can be different even if the argument's signature is OK.
Diffstat (limited to 'test')
-rw-r--r--test/ctor-eval/bad-indirect-call3.wast16
-rw-r--r--test/ctor-eval/bad-indirect-call3.wast.ctors1
-rw-r--r--test/ctor-eval/bad-indirect-call3.wast.out22
-rw-r--r--test/spec/call_indirect_sig_mismatch.wast14
4 files changed, 53 insertions, 0 deletions
diff --git a/test/ctor-eval/bad-indirect-call3.wast b/test/ctor-eval/bad-indirect-call3.wast
new file mode 100644
index 000000000..cadff8097
--- /dev/null
+++ b/test/ctor-eval/bad-indirect-call3.wast
@@ -0,0 +1,16 @@
+(module
+ (type $funcref_=>_none (func (param funcref)))
+ (memory 256 256)
+ (data (i32.const 10) "waka waka waka waka waka")
+ (table funcref (elem $callee))
+ (export "sig_mismatch" (func $sig_mismatch))
+ (func $callee (param $0 exnref)
+ (i32.store8 (i32.const 40) (i32.const 67))
+ )
+ (func $sig_mismatch
+ (call_indirect (type $funcref_=>_none) ;; unsafe to call, signature mismatch
+ (ref.null)
+ (i32.const 0)
+ )
+ )
+)
diff --git a/test/ctor-eval/bad-indirect-call3.wast.ctors b/test/ctor-eval/bad-indirect-call3.wast.ctors
new file mode 100644
index 000000000..363ce3a3c
--- /dev/null
+++ b/test/ctor-eval/bad-indirect-call3.wast.ctors
@@ -0,0 +1 @@
+sig_mismatch
diff --git a/test/ctor-eval/bad-indirect-call3.wast.out b/test/ctor-eval/bad-indirect-call3.wast.out
new file mode 100644
index 000000000..ec1d2adf6
--- /dev/null
+++ b/test/ctor-eval/bad-indirect-call3.wast.out
@@ -0,0 +1,22 @@
+(module
+ (type $none_=>_none (func))
+ (type $funcref_=>_none (func (param funcref)))
+ (type $exnref_=>_none (func (param exnref)))
+ (memory $0 256 256)
+ (data (i32.const 10) "waka waka waka waka waka")
+ (table $0 1 1 funcref)
+ (elem (i32.const 0) $callee)
+ (export "sig_mismatch" (func $sig_mismatch))
+ (func $callee (; 0 ;) (param $0 exnref)
+ (i32.store8
+ (i32.const 40)
+ (i32.const 67)
+ )
+ )
+ (func $sig_mismatch (; 1 ;)
+ (call_indirect (type $funcref_=>_none)
+ (ref.null)
+ (i32.const 0)
+ )
+ )
+)
diff --git a/test/spec/call_indirect_sig_mismatch.wast b/test/spec/call_indirect_sig_mismatch.wast
new file mode 100644
index 000000000..15e5d6a5a
--- /dev/null
+++ b/test/spec/call_indirect_sig_mismatch.wast
@@ -0,0 +1,14 @@
+(module
+ (type $funcref_=>_none (func (param funcref)))
+ (table funcref (elem $callee))
+ (export "sig_mismatch" (func $sig_mismatch))
+ (func $callee (param $0 exnref))
+ (func $sig_mismatch
+ (call_indirect (type $funcref_=>_none)
+ (ref.null)
+ (i32.const 0)
+ )
+ )
+)
+
+(assert_trap (invoke "sig_mismatch") "callIndirect: function signatures don't match")