4 (func (export "call") (result i32) (call $g))
5 (func $g (result i32) (i32.const 2))
10 (func $f (import "Mf" "call") (result i32))
11 (export "Mf.call" (func $f))
12 (func (export "call Mf.call") (result i32) (call $f))
13 (func (export "call") (result i32) (call $g))
14 (func $g (result i32) (i32.const 3))
17 (assert_return (invoke $Mf "call") (i32.const 2))
18 (assert_return (invoke $Nf "Mf.call") (i32.const 2))
19 (assert_return (invoke $Nf "call") (i32.const 3))
20 (assert_return (invoke $Nf "call Mf.call") (i32.const 2))
23 (import "spectest" "print_i32" (func $f (param i32)))
24 (export "print" (func $f))
26 (register "reexport_f")
28 (module (import "reexport_f" "print" (func (param i64))))
29 "incompatible import type"
32 (module (import "reexport_f" "print" (func (param i32) (result i32))))
33 "incompatible import type"
40 (global $glob (export "glob") i32 (i32.const 42))
41 (func (export "get") (result i32) (global.get $glob))
43 ;; export mutable globals
44 (global $mut_glob (export "mut_glob") (mut i32) (i32.const 142))
45 (func (export "get_mut") (result i32) (global.get $mut_glob))
46 (func (export "set_mut") (param i32) (global.set $mut_glob (local.get 0)))
51 (global $x (import "Mg" "glob") i32)
52 (global $mut_glob (import "Mg" "mut_glob") (mut i32))
53 (func $f (import "Mg" "get") (result i32))
54 (func $get_mut (import "Mg" "get_mut") (result i32))
55 (func $set_mut (import "Mg" "set_mut") (param i32))
57 (export "Mg.glob" (global $x))
58 (export "Mg.get" (func $f))
59 (global $glob (export "glob") i32 (i32.const 43))
60 (func (export "get") (result i32) (global.get $glob))
62 (export "Mg.mut_glob" (global $mut_glob))
63 (export "Mg.get_mut" (func $get_mut))
64 (export "Mg.set_mut" (func $set_mut))
67 (assert_return (get $Mg "glob") (i32.const 42))
68 (assert_return (get $Ng "Mg.glob") (i32.const 42))
69 (assert_return (get $Ng "glob") (i32.const 43))
70 (assert_return (invoke $Mg "get") (i32.const 42))
71 (assert_return (invoke $Ng "Mg.get") (i32.const 42))
72 (assert_return (invoke $Ng "get") (i32.const 43))
74 (assert_return (get $Mg "mut_glob") (i32.const 142))
75 (assert_return (get $Ng "Mg.mut_glob") (i32.const 142))
76 (assert_return (invoke $Mg "get_mut") (i32.const 142))
77 (assert_return (invoke $Ng "Mg.get_mut") (i32.const 142))
79 (assert_return (invoke $Mg "set_mut" (i32.const 241)))
80 (assert_return (get $Mg "mut_glob") (i32.const 241))
81 (assert_return (get $Ng "Mg.mut_glob") (i32.const 241))
82 (assert_return (invoke $Mg "get_mut") (i32.const 241))
83 (assert_return (invoke $Ng "Mg.get_mut") (i32.const 241))
87 (module (import "Mg" "mut_glob" (global i32)))
88 "incompatible import type"
91 (module (import "Mg" "glob" (global (mut i32))))
92 "incompatible import type"
98 (func $f) (elem declare func $f)
99 (global (export "g-const-funcnull") (ref null func) (ref.null func))
100 (global (export "g-const-func") (ref func) (ref.func $f))
101 (global (export "g-const-refnull") (ref null $t) (ref.null $t))
102 (global (export "g-const-ref") (ref $t) (ref.func $f))
103 (global (export "g-const-extern") externref (ref.null extern))
104 (global (export "g-var-funcnull") (mut (ref null func)) (ref.null func))
105 (global (export "g-var-func") (mut (ref func)) (ref.func $f))
106 (global (export "g-var-refnull") (mut (ref null $t)) (ref.null $t))
107 (global (export "g-var-ref") (mut (ref $t)) (ref.func $f))
108 (global (export "g-var-extern") (mut externref) (ref.null extern))
110 (register "Mref_ex" $Mref_ex)
114 (global (import "Mref_ex" "g-const-funcnull") (ref null func))
115 (global (import "Mref_ex" "g-const-func") (ref null func))
116 (global (import "Mref_ex" "g-const-refnull") (ref null func))
117 (global (import "Mref_ex" "g-const-ref") (ref null func))
118 (global (import "Mref_ex" "g-const-func") (ref func))
119 (global (import "Mref_ex" "g-const-ref") (ref func))
120 (global (import "Mref_ex" "g-const-refnull") (ref null $t))
121 (global (import "Mref_ex" "g-const-ref") (ref null $t))
122 (global (import "Mref_ex" "g-const-ref") (ref $t))
123 (global (import "Mref_ex" "g-const-extern") externref)
125 (global (import "Mref_ex" "g-var-funcnull") (mut (ref null func)))
126 (global (import "Mref_ex" "g-var-func") (mut (ref func)))
127 (global (import "Mref_ex" "g-var-refnull") (mut (ref null $t)))
128 (global (import "Mref_ex" "g-var-ref") (mut (ref $t)))
129 (global (import "Mref_ex" "g-var-extern") (mut externref))
133 (module (global (import "Mref_ex" "g-const-extern") (ref null func)))
134 "incompatible import type"
138 (module (type $t (func)) (global (import "Mref_ex" "g-const-funcnull") (ref func)))
139 "incompatible import type"
142 (module (type $t (func)) (global (import "Mref_ex" "g-const-refnull") (ref func)))
143 "incompatible import type"
146 (module (type $t (func)) (global (import "Mref_ex" "g-const-extern") (ref func)))
147 "incompatible import type"
151 (module (type $t (func)) (global (import "Mref_ex" "g-const-funcnull") (ref null $t)))
152 "incompatible import type"
155 (module (type $t (func)) (global (import "Mref_ex" "g-const-func") (ref null $t)))
156 "incompatible import type"
159 (module (type $t (func)) (global (import "Mref_ex" "g-const-extern") (ref null $t)))
160 "incompatible import type"
164 (module (type $t (func)) (global (import "Mref_ex" "g-const-funcnull") (ref $t)))
165 "incompatible import type"
168 (module (type $t (func)) (global (import "Mref_ex" "g-const-func") (ref $t)))
169 "incompatible import type"
172 (module (type $t (func)) (global (import "Mref_ex" "g-const-refnull") (ref $t)))
173 "incompatible import type"
176 (module (type $t (func)) (global (import "Mref_ex" "g-const-extern") (ref $t)))
177 "incompatible import type"
181 (module (global (import "Mref_ex" "g-const-funcnull") externref))
182 "incompatible import type"
185 (module (global (import "Mref_ex" "g-const-func") externref))
186 "incompatible import type"
189 (module (global (import "Mref_ex" "g-const-refnull") externref))
190 "incompatible import type"
193 (module (global (import "Mref_ex" "g-const-ref") externref))
194 "incompatible import type"
199 (module (global (import "Mref_ex" "g-var-func") (mut (ref null func))))
200 "incompatible import type"
203 (module (global (import "Mref_ex" "g-var-refnull") (mut (ref null func))))
204 "incompatible import type"
207 (module (global (import "Mref_ex" "g-var-ref") (mut (ref null func))))
208 "incompatible import type"
211 (module (global (import "Mref_ex" "g-var-extern") (mut (ref null func))))
212 "incompatible import type"
216 (module (global (import "Mref_ex" "g-var-funcnull") (mut (ref func))))
217 "incompatible import type"
220 (module (global (import "Mref_ex" "g-var-refnull") (mut (ref func))))
221 "incompatible import type"
224 (module (global (import "Mref_ex" "g-var-ref") (mut (ref func))))
225 "incompatible import type"
228 (module (global (import "Mref_ex" "g-var-extern") (mut (ref func))))
229 "incompatible import type"
233 (module (type $t (func)) (global (import "Mref_ex" "g-var-funcnull") (mut (ref null $t))))
234 "incompatible import type"
237 (module (type $t (func)) (global (import "Mref_ex" "g-var-func") (mut (ref null $t))))
238 "incompatible import type"
241 (module (type $t (func)) (global (import "Mref_ex" "g-var-ref") (mut (ref null $t))))
242 "incompatible import type"
245 (module (type $t (func)) (global (import "Mref_ex" "g-var-extern") (mut (ref null $t))))
246 "incompatible import type"
250 (module (type $t (func)) (global (import "Mref_ex" "g-var-funcnull") (mut (ref $t))))
251 "incompatible import type"
254 (module (type $t (func)) (global (import "Mref_ex" "g-var-func") (mut (ref $t))))
255 "incompatible import type"
258 (module (type $t (func)) (global (import "Mref_ex" "g-var-refnull") (mut (ref $t))))
259 "incompatible import type"
262 (module (type $t (func)) (global (import "Mref_ex" "g-var-extern") (mut (ref $t))))
263 "incompatible import type"
267 (module (global (import "Mref_ex" "g-var-funcnull") (mut externref)))
268 "incompatible import type"
271 (module (global (import "Mref_ex" "g-var-func") (mut externref)))
272 "incompatible import type"
275 (module (global (import "Mref_ex" "g-var-refnull") (mut externref)))
276 "incompatible import type"
279 (module (global (import "Mref_ex" "g-var-ref") (mut externref)))
280 "incompatible import type"
287 (type (func (result i32)))
290 (table (export "tab") 10 funcref)
291 (elem (i32.const 2) $g $g $g $g)
292 (func $g (result i32) (i32.const 4))
293 (func (export "h") (result i32) (i32.const -4))
295 (func (export "call") (param i32) (result i32)
296 (call_indirect (type 0) (local.get 0))
303 (type (func (result i32)))
305 (func $f (import "Mt" "call") (param i32) (result i32))
306 (func $h (import "Mt" "h") (result i32))
308 (table funcref (elem $g $g $g $h $f))
309 (func $g (result i32) (i32.const 5))
311 (export "Mt.call" (func $f))
312 (func (export "call Mt.call") (param i32) (result i32)
313 (call $f (local.get 0))
315 (func (export "call") (param i32) (result i32)
316 (call_indirect (type 1) (local.get 0))
320 (assert_return (invoke $Mt "call" (i32.const 2)) (i32.const 4))
321 (assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const 4))
322 (assert_return (invoke $Nt "call" (i32.const 2)) (i32.const 5))
323 (assert_return (invoke $Nt "call Mt.call" (i32.const 2)) (i32.const 4))
325 (assert_trap (invoke $Mt "call" (i32.const 1)) "uninitialized")
326 (assert_trap (invoke $Nt "Mt.call" (i32.const 1)) "uninitialized")
327 (assert_return (invoke $Nt "call" (i32.const 1)) (i32.const 5))
328 (assert_trap (invoke $Nt "call Mt.call" (i32.const 1)) "uninitialized")
330 (assert_trap (invoke $Mt "call" (i32.const 0)) "uninitialized")
331 (assert_trap (invoke $Nt "Mt.call" (i32.const 0)) "uninitialized")
332 (assert_return (invoke $Nt "call" (i32.const 0)) (i32.const 5))
333 (assert_trap (invoke $Nt "call Mt.call" (i32.const 0)) "uninitialized")
335 (assert_trap (invoke $Mt "call" (i32.const 20)) "undefined")
336 (assert_trap (invoke $Nt "Mt.call" (i32.const 20)) "undefined")
337 (assert_trap (invoke $Nt "call" (i32.const 7)) "undefined")
338 (assert_trap (invoke $Nt "call Mt.call" (i32.const 20)) "undefined")
340 (assert_return (invoke $Nt "call" (i32.const 3)) (i32.const -4))
341 (assert_trap (invoke $Nt "call" (i32.const 4)) "indirect call")
344 (type (func (result i32)))
346 (func $h (import "Mt" "h") (result i32))
347 (table (import "Mt" "tab") 5 funcref)
348 (elem (i32.const 1) $i $h)
349 (func $i (result i32) (i32.const 6))
351 (func (export "call") (param i32) (result i32)
352 (call_indirect (type 0) (local.get 0))
356 (assert_return (invoke $Mt "call" (i32.const 3)) (i32.const 4))
357 (assert_return (invoke $Nt "Mt.call" (i32.const 3)) (i32.const 4))
358 (assert_return (invoke $Nt "call Mt.call" (i32.const 3)) (i32.const 4))
359 (assert_return (invoke $Ot "call" (i32.const 3)) (i32.const 4))
361 (assert_return (invoke $Mt "call" (i32.const 2)) (i32.const -4))
362 (assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const -4))
363 (assert_return (invoke $Nt "call" (i32.const 2)) (i32.const 5))
364 (assert_return (invoke $Nt "call Mt.call" (i32.const 2)) (i32.const -4))
365 (assert_return (invoke $Ot "call" (i32.const 2)) (i32.const -4))
367 (assert_return (invoke $Mt "call" (i32.const 1)) (i32.const 6))
368 (assert_return (invoke $Nt "Mt.call" (i32.const 1)) (i32.const 6))
369 (assert_return (invoke $Nt "call" (i32.const 1)) (i32.const 5))
370 (assert_return (invoke $Nt "call Mt.call" (i32.const 1)) (i32.const 6))
371 (assert_return (invoke $Ot "call" (i32.const 1)) (i32.const 6))
373 (assert_trap (invoke $Mt "call" (i32.const 0)) "uninitialized")
374 (assert_trap (invoke $Nt "Mt.call" (i32.const 0)) "uninitialized")
375 (assert_return (invoke $Nt "call" (i32.const 0)) (i32.const 5))
376 (assert_trap (invoke $Nt "call Mt.call" (i32.const 0)) "uninitialized")
377 (assert_trap (invoke $Ot "call" (i32.const 0)) "uninitialized")
379 (assert_trap (invoke $Ot "call" (i32.const 20)) "undefined")
382 (table (import "Mt" "tab") 0 funcref)
383 (elem (i32.const 9) $f)
387 (module $G1 (global (export "g") i32 (i32.const 5)))
390 (global (import "G1" "g") i32)
391 (global (export "g") i32 (global.get 0))
393 (assert_return (get $G2 "g") (i32.const 5))
397 (table (import "Mt" "tab") 0 funcref)
398 (elem (i32.const 10) $f)
406 (table (import "Mt" "tab") 10 funcref)
407 (memory (import "Mt" "mem") 1) ;; does not exist
408 (func $f (result i32) (i32.const 0))
409 (elem (i32.const 7) $f)
410 (elem (i32.const 9) $f)
414 (assert_trap (invoke $Mt "call" (i32.const 7)) "uninitialized")
416 ;; Unlike in the v1 spec, active element segments stored before an
417 ;; out-of-bounds access persist after the instantiation failure.
420 (table (import "Mt" "tab") 10 funcref)
421 (func $f (result i32) (i32.const 0))
422 (elem (i32.const 7) $f)
423 (elem (i32.const 8) $f $f $f $f $f) ;; (partially) out of bounds
427 (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0))
428 (assert_trap (invoke $Mt "call" (i32.const 8)) "uninitialized")
432 (table (import "Mt" "tab") 10 funcref)
433 (func $f (result i32) (i32.const 0))
434 (elem (i32.const 7) $f)
436 (data (i32.const 0x10000) "d") ;; out of bounds
440 (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0))
445 (table (export "t-funcnull") 1 (ref null func))
446 (table (export "t-refnull") 1 (ref null $t))
447 (table (export "t-extern") 1 externref)
449 (register "Mtable_ex" $Mtable_ex)
453 (table (import "Mtable_ex" "t-funcnull") 1 (ref null func))
454 (table (import "Mtable_ex" "t-refnull") 1 (ref null $t))
455 (table (import "Mtable_ex" "t-extern") 1 externref)
459 (module (table (import "Mtable_ex" "t-refnull") 1 (ref null func)))
460 "incompatible import type"
463 (module (table (import "Mtable_ex" "t-extern") 1 (ref null func)))
464 "incompatible import type"
468 (module (type $t (func)) (table (import "Mtable_ex" "t-funcnull") 1 (ref null $t)))
469 "incompatible import type"
472 (module (type $t (func)) (table (import "Mtable_ex" "t-extern") 1 (ref null $t)))
473 "incompatible import type"
477 (module (table (import "Mtable_ex" "t-funcnull") 1 externref))
478 "incompatible import type"
481 (module (table (import "Mtable_ex" "t-refnull") 1 externref))
482 "incompatible import type"
489 (memory (export "mem") 1 5)
490 (data (i32.const 10) "\00\01\02\03\04\05\06\07\08\09")
492 (func (export "load") (param $a i32) (result i32)
493 (i32.load8_u (local.get 0))
499 (func $loadM (import "Mm" "load") (param i32) (result i32))
502 (data (i32.const 10) "\f0\f1\f2\f3\f4\f5")
504 (export "Mm.load" (func $loadM))
505 (func (export "load") (param $a i32) (result i32)
506 (i32.load8_u (local.get 0))
510 (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 2))
511 (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 2))
512 (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2))
515 (memory (import "Mm" "mem") 1)
516 (data (i32.const 5) "\a0\a1\a2\a3\a4\a5\a6\a7")
518 (func (export "load") (param $a i32) (result i32)
519 (i32.load8_u (local.get 0))
523 (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7))
524 (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7))
525 (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2))
526 (assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7))
529 (memory (import "Mm" "mem") 0)
530 (data (i32.const 0xffff) "a")
535 (memory (import "Mm" "mem") 0)
536 (data (i32.const 0x10000) "a")
542 (memory (import "Mm" "mem") 1 8)
544 (func (export "grow") (param $a i32) (result i32)
545 (memory.grow (local.get 0))
549 (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1))
550 (assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1))
551 (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 3))
552 (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const 3))
553 (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const 4))
554 (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5))
555 (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1))
556 (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5))
560 (func $host (import "spectest" "print"))
561 (memory (import "Mm" "mem") 1)
562 (table (import "Mm" "tab") 0 funcref) ;; does not exist
563 (data (i32.const 0) "abc")
567 (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 0))
569 ;; Unlike in v1 spec, active data segments written before an
570 ;; out-of-bounds access persist after the instantiation failure.
573 ;; Note: the memory is 5 pages large by the time we get here.
574 (memory (import "Mm" "mem") 1)
575 (data (i32.const 0) "abc")
576 (data (i32.const 327670) "zzzzzzzzzzzzzzzzzz") ;; (partially) out of bounds
580 (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97))
581 (assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0))
585 (memory (import "Mm" "mem") 1)
586 (data (i32.const 0) "abc")
589 (elem (i32.const 0) 0) ;; out of bounds
593 (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97))
595 ;; Store is modified if the start function traps.
597 (type $t (func (result i32)))
598 (memory (export "memory") 1)
599 (table (export "table") 1 funcref)
600 (func (export "get memory[0]") (type $t)
601 (i32.load8_u (i32.const 0))
603 (func (export "get table[0]") (type $t)
604 (call_indirect (type $t) (i32.const 0))
611 (import "Ms" "memory" (memory 1))
612 (import "Ms" "table" (table 1 funcref))
613 (data (i32.const 0) "hello")
614 (elem (i32.const 0) $f)
615 (func $f (result i32)
626 (assert_return (invoke $Ms "get memory[0]") (i32.const 104)) ;; 'h'
627 (assert_return (invoke $Ms "get table[0]") (i32.const 0xdead))