1;;! reference_types = true
2
3(module
4  (global $g (mut externref) (ref.null extern))
5
6  ;; This function will have a stack map, notably one that's a bit
7  ;; different than the one below.
8  (func $has_a_stack_map
9      (local externref)
10      global.get $g
11      local.tee 0
12      global.set $g
13
14      local.get 0
15      global.set $g
16      ref.null extern
17      global.set $g
18  )
19
20  ;; This function also has a stack map, but it's only applicable after
21  ;; the call to the `$gc` import, so when we gc during that we shouldn't
22  ;; accidentally read the previous function's stack maps and use that
23  ;; for our own.
24  (func (export "run") (result i32)
25      call $gc
26
27      ref.null extern
28      global.set $g
29      i32.const 0
30  )
31
32  (func (export "init") (param externref)
33      local.get 0
34      global.set $g
35  )
36
37  ;; A small function which when run triggers a gc in wasmtime
38  (func $gc
39    (local $i i32)
40    i32.const 10000
41    local.set $i
42    (loop $continue
43      (global.set $g (global.get $g))
44      (local.tee $i (i32.sub (local.get $i) (i32.const 1)))
45      br_if $continue
46    )
47  )
48)
49
50(invoke "init" (ref.extern 1))
51(assert_return (invoke "run") (i32.const 0))
52