1 ;; Test the element section
11 (elem funcref (ref.func $f) (item ref.func $f) (item (ref.null func)) (ref.func $g))
13 (elem func $f $f $g $g)
16 (elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
18 (elem $p4 func $f $f $g $g)
21 (elem (table $t) (i32.const 0) funcref)
22 (elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
23 (elem (table $t) (i32.const 0) func)
24 (elem (table $t) (i32.const 0) func $f $g)
25 (elem (table $t) (offset (i32.const 0)) funcref)
26 (elem (table $t) (offset (i32.const 0)) func $f $g)
27 (elem (table 0) (i32.const 0) func)
28 (elem (table 0x0) (i32.const 0) func $f $f)
29 (elem (table 0x000) (offset (i32.const 0)) func)
30 (elem (table 0) (offset (i32.const 0)) func $f $f)
31 (elem (table $t) (i32.const 0) func)
32 (elem (table $t) (i32.const 0) func $f $f)
33 (elem (table $t) (offset (i32.const 0)) func)
34 (elem (table $t) (offset (i32.const 0)) func $f $f)
35 (elem (offset (i32.const 0)))
36 (elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
37 (elem (offset (i32.const 0)) func $f $f)
38 (elem (offset (i32.const 0)) $f $f)
40 (elem (i32.const 0) funcref (ref.func $f) (ref.null func))
41 (elem (i32.const 0) func $f $f)
42 (elem (i32.const 0) $f $f)
44 (elem $a1 (table $t) (i32.const 0) funcref)
45 (elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
46 (elem $a3 (table $t) (i32.const 0) func)
47 (elem $a4 (table $t) (i32.const 0) func $f $g)
48 (elem $a9 (table $t) (offset (i32.const 0)) funcref)
49 (elem $a10 (table $t) (offset (i32.const 0)) func $f $g)
50 (elem $a11 (table 0) (i32.const 0) func)
51 (elem $a12 (table 0x0) (i32.const 0) func $f $f)
52 (elem $a13 (table 0x000) (offset (i32.const 0)) func)
53 (elem $a14 (table 0) (offset (i32.const 0)) func $f $f)
54 (elem $a15 (table $t) (i32.const 0) func)
55 (elem $a16 (table $t) (i32.const 0) func $f $f)
56 (elem $a17 (table $t) (offset (i32.const 0)) func)
57 (elem $a18 (table $t) (offset (i32.const 0)) func $f $f)
58 (elem $a19 (offset (i32.const 0)))
59 (elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
60 (elem $a21 (offset (i32.const 0)) func $f $f)
61 (elem $a22 (offset (i32.const 0)) $f $f)
62 (elem $a23 (i32.const 0))
63 (elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null func))
64 (elem $a25 (i32.const 0) func $f $f)
65 (elem $a26 (i32.const 0) $f $f)
68 (elem declare funcref)
69 (elem declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
71 (elem declare func $f $f $g $g)
73 (elem $d1 declare funcref)
74 (elem $d2 declare funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
75 (elem $d3 declare func)
76 (elem $d4 declare func $f $f $g $g)
83 (table $t funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
92 (elem (i32.const 0) $f)
95 (import "spectest" "table" (table 10 funcref))
97 (elem (i32.const 0) $f)
103 (elem (i32.const 0) $f)
104 (elem (i32.const 3) $f)
105 (elem (i32.const 7) $f)
106 (elem (i32.const 5) $f)
107 (elem (i32.const 3) $f)
110 (import "spectest" "table" (table 10 funcref))
112 (elem (i32.const 9) $f)
113 (elem (i32.const 3) $f)
114 (elem (i32.const 7) $f)
115 (elem (i32.const 3) $f)
116 (elem (i32.const 5) $f)
120 (global (import "spectest" "global_i32") i32)
123 (elem (global.get 0) $f)
127 (global $g (import "spectest" "global_i32") i32)
130 (elem (global.get $g) $f)
134 (type $out-i32 (func (result i32)))
136 (elem (i32.const 7) $const-i32-a)
137 (elem (i32.const 9) $const-i32-b)
138 (func $const-i32-a (type $out-i32) (i32.const 65))
139 (func $const-i32-b (type $out-i32) (i32.const 66))
140 (func (export "call-7") (type $out-i32)
141 (call_indirect (type $out-i32) (i32.const 7))
143 (func (export "call-9") (type $out-i32)
144 (call_indirect (type $out-i32) (i32.const 9))
147 (assert_return (invoke "call-7") (i32.const 65))
148 (assert_return (invoke "call-9") (i32.const 66))
155 (elem (i32.const 9) $f)
158 (import "spectest" "table" (table 10 funcref))
160 (elem (i32.const 9) $f)
168 (import "spectest" "table" (table 0 funcref))
179 (elem (i32.const 20))
183 (import "spectest" "table" (table 0 funcref))
185 (elem (i32.const 0) $f)
189 (import "spectest" "table" (table 0 100 funcref))
191 (elem (i32.const 0) $f)
195 (import "spectest" "table" (table 0 funcref))
197 (elem (i32.const 1) $f)
201 (import "spectest" "table" (table 0 30 funcref))
203 (elem (i32.const 1) $f)
206 ;; Invalid bounds for elements
212 (elem (i32.const 0) $f)
221 (elem (i32.const 0) $f)
230 (elem (i32.const 0) $f)
246 (elem (i32.const 10) $f)
252 (import "spectest" "table" (table 10 funcref))
254 (elem (i32.const 10) $f)
261 (table 10 20 funcref)
263 (elem (i32.const 10) $f)
269 (import "spectest" "table" (table 10 funcref))
271 (elem (i32.const 10) $f)
280 (elem (i32.const -1) $f)
286 (import "spectest" "table" (table 10 funcref))
288 (elem (i32.const -1) $f)
297 (elem (i32.const -10) $f)
303 (import "spectest" "table" (table 10 funcref))
305 (elem (i32.const -10) $f)
310 ;; Implicitly dropped elements
314 (elem $e (i32.const 0) func $f)
316 (func (export "init")
317 (table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
320 (assert_trap (invoke "init") "out of bounds")
324 (elem $e declare func $f)
326 (func (export "init")
327 (table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
330 (assert_trap (invoke "init") "out of bounds")
332 ;; Element without table
337 (elem (i32.const 0) $f)
355 (elem (i32.ctz (i32.const 0)))
357 "constant expression required"
365 "constant expression required"
371 (elem (offset (nop) (i32.const 0)))
373 "constant expression required"
379 (elem (offset (i32.const 0) (nop)))
381 "constant expression required"
384 ;; Use of internal globals in constant expressions is not allowed in MVP.
386 ;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
387 ;; "constant expression required"
390 ;; Two elements target the same slot
393 (type $out-i32 (func (result i32)))
395 (elem (i32.const 9) $const-i32-a)
396 (elem (i32.const 9) $const-i32-b)
397 (func $const-i32-a (type $out-i32) (i32.const 65))
398 (func $const-i32-b (type $out-i32) (i32.const 66))
399 (func (export "call-overwritten") (type $out-i32)
400 (call_indirect (type $out-i32) (i32.const 9))
403 (assert_return (invoke "call-overwritten") (i32.const 66))
406 (type $out-i32 (func (result i32)))
407 (import "spectest" "table" (table 10 funcref))
408 (elem (i32.const 9) $const-i32-a)
409 (elem (i32.const 9) $const-i32-b)
410 (func $const-i32-a (type $out-i32) (i32.const 65))
411 (func $const-i32-b (type $out-i32) (i32.const 66))
412 (func (export "call-overwritten-element") (type $out-i32)
413 (call_indirect (type $out-i32) (i32.const 9))
416 (assert_return (invoke "call-overwritten-element") (i32.const 66))
418 ;; Element sections across multiple modules change the same table
421 (type $out-i32 (func (result i32)))
422 (table (export "shared-table") 10 funcref)
423 (elem (i32.const 8) $const-i32-a)
424 (elem (i32.const 9) $const-i32-b)
425 (func $const-i32-a (type $out-i32) (i32.const 65))
426 (func $const-i32-b (type $out-i32) (i32.const 66))
427 (func (export "call-7") (type $out-i32)
428 (call_indirect (type $out-i32) (i32.const 7))
430 (func (export "call-8") (type $out-i32)
431 (call_indirect (type $out-i32) (i32.const 8))
433 (func (export "call-9") (type $out-i32)
434 (call_indirect (type $out-i32) (i32.const 9))
438 (register "module1" $module1)
440 (assert_trap (invoke $module1 "call-7") "uninitialized element")
441 (assert_return (invoke $module1 "call-8") (i32.const 65))
442 (assert_return (invoke $module1 "call-9") (i32.const 66))
445 (type $out-i32 (func (result i32)))
446 (import "module1" "shared-table" (table 10 funcref))
447 (elem (i32.const 7) $const-i32-c)
448 (elem (i32.const 8) $const-i32-d)
449 (func $const-i32-c (type $out-i32) (i32.const 67))
450 (func $const-i32-d (type $out-i32) (i32.const 68))
453 (assert_return (invoke $module1 "call-7") (i32.const 67))
454 (assert_return (invoke $module1 "call-8") (i32.const 68))
455 (assert_return (invoke $module1 "call-9") (i32.const 66))
458 (type $out-i32 (func (result i32)))
459 (import "module1" "shared-table" (table 10 funcref))
460 (elem (i32.const 8) $const-i32-e)
461 (elem (i32.const 9) $const-i32-f)
462 (func $const-i32-e (type $out-i32) (i32.const 69))
463 (func $const-i32-f (type $out-i32) (i32.const 70))
466 (assert_return (invoke $module1 "call-7") (i32.const 67))
467 (assert_return (invoke $module1 "call-8") (i32.const 69))
468 (assert_return (invoke $module1 "call-9") (i32.const 70))