1 ;; Test the element section
11 (elem funcref (ref.func $f) (ref.func $f) (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)
72 (table $t funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
79 (elem (i32.const 0) $f)
82 (import "spectest" "table" (table 10 funcref))
84 (elem (i32.const 0) $f)
90 (elem (i32.const 0) $f)
91 (elem (i32.const 3) $f)
92 (elem (i32.const 7) $f)
93 (elem (i32.const 5) $f)
94 (elem (i32.const 3) $f)
97 (import "spectest" "table" (table 10 funcref))
99 (elem (i32.const 9) $f)
100 (elem (i32.const 3) $f)
101 (elem (i32.const 7) $f)
102 (elem (i32.const 3) $f)
103 (elem (i32.const 5) $f)
107 (global (import "spectest" "global_i32") i32)
110 (elem (global.get 0) $f)
114 (global $g (import "spectest" "global_i32") i32)
117 (elem (global.get $g) $f)
121 (type $out-i32 (func (result i32)))
123 (elem (i32.const 7) $const-i32-a)
124 (elem (i32.const 9) $const-i32-b)
125 (func $const-i32-a (type $out-i32) (i32.const 65))
126 (func $const-i32-b (type $out-i32) (i32.const 66))
127 (func (export "call-7") (type $out-i32)
128 (call_indirect (type $out-i32) (i32.const 7))
130 (func (export "call-9") (type $out-i32)
131 (call_indirect (type $out-i32) (i32.const 9))
134 (assert_return (invoke "call-7") (i32.const 65))
135 (assert_return (invoke "call-9") (i32.const 66))
142 (elem (i32.const 9) $f)
145 (import "spectest" "table" (table 10 funcref))
147 (elem (i32.const 9) $f)
155 (import "spectest" "table" (table 0 funcref))
166 (elem (i32.const 20))
170 (import "spectest" "table" (table 0 funcref))
172 (elem (i32.const 0) $f)
176 (import "spectest" "table" (table 0 100 funcref))
178 (elem (i32.const 0) $f)
182 (import "spectest" "table" (table 0 funcref))
184 (elem (i32.const 1) $f)
188 (import "spectest" "table" (table 0 30 funcref))
190 (elem (i32.const 1) $f)
193 ;; Invalid bounds for elements
199 (elem (i32.const 0) $f)
208 (elem (i32.const 0) $f)
217 (elem (i32.const 0) $f)
233 (elem (i32.const 10) $f)
239 (import "spectest" "table" (table 10 funcref))
241 (elem (i32.const 10) $f)
248 (table 10 20 funcref)
250 (elem (i32.const 10) $f)
256 (import "spectest" "table" (table 10 funcref))
258 (elem (i32.const 10) $f)
267 (elem (i32.const -1) $f)
273 (import "spectest" "table" (table 10 funcref))
275 (elem (i32.const -1) $f)
284 (elem (i32.const -10) $f)
290 (import "spectest" "table" (table 10 funcref))
292 (elem (i32.const -10) $f)
297 ;; Element without table
302 (elem (i32.const 0) $f)
320 (elem (i32.ctz (i32.const 0)))
322 "constant expression required"
330 "constant expression required"
336 (elem (offset (nop) (i32.const 0)))
338 "constant expression required"
344 (elem (offset (i32.const 0) (nop)))
346 "constant expression required"
349 ;; Use of internal globals in constant expressions is not allowed in MVP.
351 ;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
352 ;; "constant expression required"
355 ;; Two elements target the same slot
358 (type $out-i32 (func (result i32)))
360 (elem (i32.const 9) $const-i32-a)
361 (elem (i32.const 9) $const-i32-b)
362 (func $const-i32-a (type $out-i32) (i32.const 65))
363 (func $const-i32-b (type $out-i32) (i32.const 66))
364 (func (export "call-overwritten") (type $out-i32)
365 (call_indirect (type $out-i32) (i32.const 9))
368 (assert_return (invoke "call-overwritten") (i32.const 66))
371 (type $out-i32 (func (result i32)))
372 (import "spectest" "table" (table 10 funcref))
373 (elem (i32.const 9) $const-i32-a)
374 (elem (i32.const 9) $const-i32-b)
375 (func $const-i32-a (type $out-i32) (i32.const 65))
376 (func $const-i32-b (type $out-i32) (i32.const 66))
377 (func (export "call-overwritten-element") (type $out-i32)
378 (call_indirect (type $out-i32) (i32.const 9))
381 (assert_return (invoke "call-overwritten-element") (i32.const 66))
383 ;; Element sections across multiple modules change the same table
386 (type $out-i32 (func (result i32)))
387 (table (export "shared-table") 10 funcref)
388 (elem (i32.const 8) $const-i32-a)
389 (elem (i32.const 9) $const-i32-b)
390 (func $const-i32-a (type $out-i32) (i32.const 65))
391 (func $const-i32-b (type $out-i32) (i32.const 66))
392 (func (export "call-7") (type $out-i32)
393 (call_indirect (type $out-i32) (i32.const 7))
395 (func (export "call-8") (type $out-i32)
396 (call_indirect (type $out-i32) (i32.const 8))
398 (func (export "call-9") (type $out-i32)
399 (call_indirect (type $out-i32) (i32.const 9))
403 (register "module1" $module1)
405 (assert_trap (invoke $module1 "call-7") "uninitialized element")
406 (assert_return (invoke $module1 "call-8") (i32.const 65))
407 (assert_return (invoke $module1 "call-9") (i32.const 66))
410 (type $out-i32 (func (result i32)))
411 (import "module1" "shared-table" (table 10 funcref))
412 (elem (i32.const 7) $const-i32-c)
413 (elem (i32.const 8) $const-i32-d)
414 (func $const-i32-c (type $out-i32) (i32.const 67))
415 (func $const-i32-d (type $out-i32) (i32.const 68))
418 (assert_return (invoke $module1 "call-7") (i32.const 67))
419 (assert_return (invoke $module1 "call-8") (i32.const 68))
420 (assert_return (invoke $module1 "call-9") (i32.const 66))
423 (type $out-i32 (func (result i32)))
424 (import "module1" "shared-table" (table 10 funcref))
425 (elem (i32.const 8) $const-i32-e)
426 (elem (i32.const 9) $const-i32-f)
427 (func $const-i32-e (type $out-i32) (i32.const 69))
428 (func $const-i32-f (type $out-i32) (i32.const 70))
431 (assert_return (invoke $module1 "call-7") (i32.const 67))
432 (assert_return (invoke $module1 "call-8") (i32.const 69))
433 (assert_return (invoke $module1 "call-9") (i32.const 70))