summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/multi-table.wast14
-rw-r--r--test/multi-table.wast.from-wast9
-rw-r--r--test/multi-table.wast.fromBinary9
-rw-r--r--test/multi-table.wast.fromBinary.noDebugInfo7
-rw-r--r--test/spec/elem_reftypes.wast263
-rw-r--r--test/spec/table.wast24
6 files changed, 318 insertions, 8 deletions
diff --git a/test/multi-table.wast b/test/multi-table.wast
index cbfa369e0..a98c9e4b0 100644
--- a/test/multi-table.wast
+++ b/test/multi-table.wast
@@ -1,7 +1,13 @@
(module
+ (type $none_=>_none (func))
+ (type $A (struct))
+ (global $g1 (ref null $none_=>_none) (ref.func $f))
+ (global $g2 i32 (i32.const 0))
+
(import "a" "b" (table $t1 1 10 funcref))
(table $t2 3 3 funcref)
(table $t3 4 4 funcref)
+ (table $textern 0 externref)
;; add to $t1
(elem (i32.const 0) $f)
@@ -10,10 +16,12 @@
(elem (table $t2) (i32.const 0) func $f)
(elem $activeNonZeroOffset (table $t2) (offset (i32.const 1)) func $f $g)
- (elem $e3-1 (table $t3) (i32.const 0) funcref (ref.func $f) (ref.null func))
- (elem $e3-2 (table $t3) (offset (i32.const 2)) funcref (item ref.func $f) (item (ref.func $g)))
+ (elem $e3-1 (table $t3) (global.get $g2) funcref (ref.func $f) (ref.null func))
+ (elem $e3-2 (table $t3) (offset (i32.const 2)) (ref null $none_=>_none) (item ref.func $f) (item (ref.func $g)))
- (elem $passive funcref (item ref.func $f) (item (ref.func $g)) (ref.null func))
+ (elem $passive-1 func $f $g)
+ (elem $passive-2 funcref (item ref.func $f) (item (ref.func $g)) (ref.null func))
+ (elem $passive-3 (ref null $none_=>_none) (item ref.func $f) (item (ref.func $g)) (ref.null $none_=>_none) (global.get $g1))
(elem $empty func)
(elem $declarative declare func $h)
diff --git a/test/multi-table.wast.from-wast b/test/multi-table.wast.from-wast
index 80c081354..34900e54c 100644
--- a/test/multi-table.wast.from-wast
+++ b/test/multi-table.wast.from-wast
@@ -2,13 +2,18 @@
(type $none_=>_none (func))
(import "a" "b" (table $t1 1 10 funcref))
(elem (table $t1) (i32.const 0) func $f)
+ (global $g1 (ref null $none_=>_none) (ref.func $f))
+ (global $g2 i32 (i32.const 0))
(table $t2 3 3 funcref)
(elem (table $t2) (i32.const 0) func $f)
(elem $activeNonZeroOffset (table $t2) (i32.const 1) func $f $g)
(table $t3 4 4 funcref)
- (elem $e3-1 (table $t3) (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem $e3-1 (table $t3) (global.get $g2) funcref (ref.func $f) (ref.null func))
(elem $e3-2 (table $t3) (i32.const 2) func $f $g)
- (elem $passive funcref (ref.func $f) (ref.func $g) (ref.null func))
+ (table $textern 0 externref)
+ (elem $passive-1 func $f $g)
+ (elem $passive-2 funcref (ref.func $f) (ref.func $g) (ref.null func))
+ (elem $passive-3 (ref null $none_=>_none) (ref.func $f) (ref.func $g) (ref.null $none_=>_none) (global.get $g1))
(elem declare func $h)
(func $f
(drop
diff --git a/test/multi-table.wast.fromBinary b/test/multi-table.wast.fromBinary
index 9918b6183..db652b8db 100644
--- a/test/multi-table.wast.fromBinary
+++ b/test/multi-table.wast.fromBinary
@@ -2,13 +2,18 @@
(type $none_=>_none (func))
(import "a" "b" (table $t1 1 10 funcref))
(elem (table $t1) (i32.const 0) func $f)
+ (global $g1 (ref null $none_=>_none) (ref.func $f))
+ (global $g2 i32 (i32.const 0))
(table $t2 3 3 funcref)
(elem (table $t2) (i32.const 0) func $f)
(elem $activeNonZeroOffset (table $t2) (i32.const 1) func $f $g)
(table $t3 4 4 funcref)
- (elem $e3-1 (table $t3) (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem $e3-1 (table $t3) (global.get $g2) funcref (ref.func $f) (ref.null func))
(elem $e3-2 (table $t3) (i32.const 2) func $f $g)
- (elem $passive funcref (ref.func $f) (ref.func $g) (ref.null func))
+ (table $textern 0 externref)
+ (elem $passive-1 func $f $g)
+ (elem $passive-2 funcref (ref.func $f) (ref.func $g) (ref.null func))
+ (elem $passive-3 (ref null $none_=>_none) (ref.func $f) (ref.func $g) (ref.null $none_=>_none) (global.get $g1))
(elem declare func $h)
(func $f
(drop
diff --git a/test/multi-table.wast.fromBinary.noDebugInfo b/test/multi-table.wast.fromBinary.noDebugInfo
index 638ee7329..4125f5ee8 100644
--- a/test/multi-table.wast.fromBinary.noDebugInfo
+++ b/test/multi-table.wast.fromBinary.noDebugInfo
@@ -2,13 +2,18 @@
(type $none_=>_none (func))
(import "a" "b" (table $timport$0 1 10 funcref))
(elem (table $timport$0) (i32.const 0) func $0)
+ (global $global$0 (ref null $none_=>_none) (ref.func $0))
+ (global $global$1 i32 (i32.const 0))
(table $0 3 3 funcref)
(elem (table $0) (i32.const 0) func $0)
(elem (table $0) (i32.const 1) func $0 $1)
(table $1 4 4 funcref)
- (elem (table $1) (i32.const 0) funcref (ref.func $0) (ref.null func))
+ (elem (table $1) (global.get $global$1) funcref (ref.func $0) (ref.null func))
(elem (table $1) (i32.const 2) func $0 $1)
+ (table $2 0 externref)
+ (elem func $0 $1)
(elem funcref (ref.func $0) (ref.func $1) (ref.null func))
+ (elem (ref null $none_=>_none) (ref.func $0) (ref.func $1) (ref.null $none_=>_none) (global.get $global$0))
(elem declare func $2)
(func $0
(drop
diff --git a/test/spec/elem_reftypes.wast b/test/spec/elem_reftypes.wast
new file mode 100644
index 000000000..9efc4d59f
--- /dev/null
+++ b/test/spec/elem_reftypes.wast
@@ -0,0 +1,263 @@
+;; Test the element section
+
+;; Syntax
+(module
+ (table $t 10 funcref)
+ (func $f)
+ (func $g)
+
+ ;; Passive
+ (elem funcref)
+ (elem funcref (ref.func $f) (item ref.func $f) (item (ref.null func)) (ref.func $g))
+ (elem func)
+ (elem func $f $f $g $g)
+
+ (elem $p1 funcref)
+ (elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
+ (elem $p3 func)
+ (elem $p4 func $f $f $g $g)
+
+ ;; Active
+ (elem (table $t) (i32.const 0) funcref)
+ (elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem (table $t) (i32.const 0) func)
+ (elem (table $t) (i32.const 0) func $f $g)
+ (elem (table $t) (offset (i32.const 0)) funcref)
+ (elem (table $t) (offset (i32.const 0)) func $f $g)
+ (elem (table 0) (i32.const 0) func)
+ ;; (elem (table 0x0) (i32.const 0) func $f $f)
+ ;; (elem (table 0x000) (offset (i32.const 0)) func)
+ (elem (table 0) (offset (i32.const 0)) func $f $f)
+ (elem (table $t) (i32.const 0) func)
+ (elem (table $t) (i32.const 0) func $f $f)
+ (elem (table $t) (offset (i32.const 0)) func)
+ (elem (table $t) (offset (i32.const 0)) func $f $f)
+ (elem (offset (i32.const 0)))
+ (elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
+ (elem (offset (i32.const 0)) func $f $f)
+ (elem (offset (i32.const 0)) $f $f)
+ (elem (i32.const 0))
+ (elem (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem (i32.const 0) func $f $f)
+ (elem (i32.const 0) $f $f)
+
+ (elem $a1 (table $t) (i32.const 0) funcref)
+ (elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem $a3 (table $t) (i32.const 0) func)
+ (elem $a4 (table $t) (i32.const 0) func $f $g)
+ (elem $a9 (table $t) (offset (i32.const 0)) funcref)
+ (elem $a10 (table $t) (offset (i32.const 0)) func $f $g)
+ (elem $a11 (table 0) (i32.const 0) func)
+ ;; (elem $a12 (table 0x0) (i32.const 0) func $f $f)
+ ;; (elem $a13 (table 0x000) (offset (i32.const 0)) func)
+ (elem $a14 (table 0) (offset (i32.const 0)) func $f $f)
+ (elem $a15 (table $t) (i32.const 0) func)
+ (elem $a16 (table $t) (i32.const 0) func $f $f)
+ (elem $a17 (table $t) (offset (i32.const 0)) func)
+ (elem $a18 (table $t) (offset (i32.const 0)) func $f $f)
+ (elem $a19 (offset (i32.const 0)))
+ (elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
+ (elem $a21 (offset (i32.const 0)) func $f $f)
+ (elem $a22 (offset (i32.const 0)) $f $f)
+ (elem $a23 (i32.const 0))
+ (elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null func))
+ (elem $a25 (i32.const 0) func $f $f)
+ (elem $a26 (i32.const 0) $f $f)
+
+ ;; Declarative
+ (elem declare funcref)
+ (elem declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
+ (elem declare func)
+ (elem declare func $f $f $g $g)
+
+ (elem $d1 declare funcref)
+ (elem $d2 declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
+ (elem $d3 declare func)
+ (elem $d4 declare func $f $f $g $g)
+)
+
+(module
+ (func $f)
+ (func $g)
+
+ (table $t1 funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
+ (table $t2 (ref null func) (elem (ref.func $f) (ref.null func) (ref.func $g)))
+)
+
+
+;; Basic use
+
+(module
+ (table 10 funcref)
+ (func $f)
+ (elem (i32.const 0) $f)
+)
+(module
+ (import "spectest" "table" (table 10 funcref))
+ (func $f)
+ (elem (i32.const 0) $f)
+)
+
+(module
+ (table 10 funcref)
+ (func $f)
+ (elem (i32.const 0) $f)
+ (elem (i32.const 3) $f)
+ (elem (i32.const 7) $f)
+ (elem (i32.const 5) $f)
+ (elem (i32.const 3) $f)
+)
+(module
+ (import "spectest" "table" (table 10 funcref))
+ (func $f)
+ (elem (i32.const 9) $f)
+ (elem (i32.const 3) $f)
+ (elem (i32.const 7) $f)
+ (elem (i32.const 3) $f)
+ (elem (i32.const 5) $f)
+)
+
+(module
+ (global (import "spectest" "global_i32") i32)
+ (table 1000 funcref)
+ (func $f)
+ (elem (global.get 0) $f)
+)
+
+(module
+ (global $g (import "spectest" "global_i32") i32)
+ (table 1000 funcref)
+ (func $f)
+ (elem (global.get $g) $f)
+)
+
+(module
+ (type $out-i32 (func (result i32)))
+ (table 10 funcref)
+ (elem (i32.const 7) $const-i32-a)
+ (elem (i32.const 9) $const-i32-b)
+ (func $const-i32-a (type $out-i32) (i32.const 65))
+ (func $const-i32-b (type $out-i32) (i32.const 66))
+ (func (export "call-7") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 7))
+ )
+ (func (export "call-9") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 9))
+ )
+)
+(assert_return (invoke "call-7") (i32.const 65))
+(assert_return (invoke "call-9") (i32.const 66))
+
+;; Corner cases
+
+(module
+ (table 10 funcref)
+ (func $f)
+ (elem (i32.const 9) $f)
+)
+(module
+ (import "spectest" "table" (table 10 funcref))
+ (func $f)
+ (elem (i32.const 9) $f)
+)
+
+(module
+ (table 0 funcref)
+ (elem (i32.const 0))
+)
+(module
+ (import "spectest" "table" (table 0 funcref))
+ (elem (i32.const 0))
+)
+
+(module
+ (table 0 0 funcref)
+ (elem (i32.const 0))
+)
+
+(module
+ (table 20 funcref)
+ (elem (i32.const 20))
+)
+
+;;; We cannot enable these yet since we check table bounds at validation stage,
+;;; which is incorrect for imported tables.
+;; (module
+;; (import "spectest" "table" (table 0 funcref))
+;; (func $f)
+;; (elem (i32.const 0) $f)
+;; )
+
+;; (module
+;; (import "spectest" "table" (table 0 100 funcref))
+;; (func $f)
+;; (elem (i32.const 0) $f)
+;; )
+
+;; (module
+;; (import "spectest" "table" (table 0 funcref))
+;; (func $f)
+;; (elem (i32.const 1) $f)
+;; )
+
+;; (module
+;; (import "spectest" "table" (table 0 30 funcref))
+;; (func $f)
+;; (elem (i32.const 1) $f)
+;; )
+
+;; Two elements target the same slot
+
+(module
+ (type $out-i32 (func (result i32)))
+ (table 10 funcref)
+ (elem (i32.const 9) $const-i32-a)
+ (elem (i32.const 9) $const-i32-b)
+ (func $const-i32-a (type $out-i32) (i32.const 65))
+ (func $const-i32-b (type $out-i32) (i32.const 66))
+ (func (export "call-overwritten") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 9))
+ )
+)
+(assert_return (invoke "call-overwritten") (i32.const 66))
+
+(module
+ (type $out-i32 (func (result i32)))
+ (import "spectest" "table" (table 10 funcref))
+ (elem (i32.const 9) $const-i32-a)
+ (elem (i32.const 9) $const-i32-b)
+ (func $const-i32-a (type $out-i32) (i32.const 65))
+ (func $const-i32-b (type $out-i32) (i32.const 66))
+ (func (export "call-overwritten-element") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 9))
+ )
+)
+(assert_return (invoke "call-overwritten-element") (i32.const 66))
+
+;; Element sections across multiple modules change the same table
+
+(module $module1
+ (type $out-i32 (func (result i32)))
+ (table (export "shared-table") 10 funcref)
+ (elem (i32.const 8) $const-i32-a)
+ (elem (i32.const 9) $const-i32-b)
+ (func $const-i32-a (type $out-i32) (i32.const 65))
+ (func $const-i32-b (type $out-i32) (i32.const 66))
+ (func (export "call-7") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 7))
+ )
+ (func (export "call-8") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 8))
+ )
+ (func (export "call-9") (type $out-i32)
+ (call_indirect (type $out-i32) (i32.const 9))
+ )
+)
+
+(assert_invalid
+ (module
+ (type $none_=>_none (func))
+ (table 0 (ref null $none_=>_none))
+ (elem (i32.const 0) funcref)
+ )
+) \ No newline at end of file
diff --git a/test/spec/table.wast b/test/spec/table.wast
new file mode 100644
index 000000000..54281a03e
--- /dev/null
+++ b/test/spec/table.wast
@@ -0,0 +1,24 @@
+
+;; Test table section structure
+
+(module (table 0 funcref))
+(module (table 0 (ref null func)))
+(module (table 1 funcref))
+(module (table 0 0 funcref))
+(module (table 0 1 funcref))
+(module (table 0 1 (ref null func)))
+(module (table 1 256 funcref))
+(module (table 0 65536 externref))
+;; (module (table 0 0xffff_ffff funcref))
+
+(module (table 0 funcref) (table 0 funcref))
+(module (table (import "spectest" "table") 0 funcref) (table 0 funcref))
+
+(assert_invalid (module (elem (i32.const 0))) "unknown table")
+(assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table")
+
+
+(assert_invalid
+ (module (table 1 0 funcref))
+ "size minimum must not be greater than maximum"
+)