Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 7cfa199

Browse files
authored
[test] call_indirect with multiple tables (#83)
1 parent a1bfe97 commit 7cfa199

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/core/call_indirect.wast

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,52 @@
588588
(assert_return (invoke "as-compare-right") (i32.const 1))
589589
(assert_return (invoke "as-convert-operand") (i64.const 1))
590590

591+
592+
;; Multiple tables
593+
594+
(module
595+
(type $ii-i (func (param i32 i32) (result i32)))
596+
597+
(table $t1 funcref (elem $f $g))
598+
(table $t2 funcref (elem $h $i $j))
599+
(table $t3 4 funcref)
600+
(elem (table $t3) (i32.const 0) func $g $h)
601+
(elem (table $t3) (i32.const 3) func $z)
602+
603+
(func $f (type $ii-i) (i32.add (local.get 0) (local.get 1)))
604+
(func $g (type $ii-i) (i32.sub (local.get 0) (local.get 1)))
605+
(func $h (type $ii-i) (i32.mul (local.get 0) (local.get 1)))
606+
(func $i (type $ii-i) (i32.div_u (local.get 0) (local.get 1)))
607+
(func $j (type $ii-i) (i32.rem_u (local.get 0) (local.get 1)))
608+
(func $z)
609+
610+
(func (export "call-1") (param i32 i32 i32) (result i32)
611+
(call_indirect $t1 (type $ii-i) (local.get 0) (local.get 1) (local.get 2))
612+
)
613+
(func (export "call-2") (param i32 i32 i32) (result i32)
614+
(call_indirect $t2 (type $ii-i) (local.get 0) (local.get 1) (local.get 2))
615+
)
616+
(func (export "call-3") (param i32 i32 i32) (result i32)
617+
(call_indirect $t3 (type $ii-i) (local.get 0) (local.get 1) (local.get 2))
618+
)
619+
)
620+
621+
(assert_return (invoke "call-1" (i32.const 2) (i32.const 3) (i32.const 0)) (i32.const 5))
622+
(assert_return (invoke "call-1" (i32.const 2) (i32.const 3) (i32.const 1)) (i32.const -1))
623+
(assert_trap (invoke "call-1" (i32.const 2) (i32.const 3) (i32.const 2)) "undefined element")
624+
625+
(assert_return (invoke "call-2" (i32.const 2) (i32.const 3) (i32.const 0)) (i32.const 6))
626+
(assert_return (invoke "call-2" (i32.const 2) (i32.const 3) (i32.const 1)) (i32.const 0))
627+
(assert_return (invoke "call-2" (i32.const 2) (i32.const 3) (i32.const 2)) (i32.const 2))
628+
(assert_trap (invoke "call-2" (i32.const 2) (i32.const 3) (i32.const 3)) "undefined element")
629+
630+
(assert_return (invoke "call-3" (i32.const 2) (i32.const 3) (i32.const 0)) (i32.const -1))
631+
(assert_return (invoke "call-3" (i32.const 2) (i32.const 3) (i32.const 1)) (i32.const 6))
632+
(assert_trap (invoke "call-3" (i32.const 2) (i32.const 3) (i32.const 2)) "uninitialized element")
633+
(assert_trap (invoke "call-3" (i32.const 2) (i32.const 3) (i32.const 3)) "indirect call type mismatch")
634+
(assert_trap (invoke "call-3" (i32.const 2) (i32.const 3) (i32.const 4)) "undefined element")
635+
636+
591637
;; Invalid syntax
592638

593639
(assert_malformed

0 commit comments

Comments
 (0)