Debian Codegraph @

tests/cli/function-references/call_ref/br_on_null.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 (module
4 (type $t (func (result i32)))
5
6 (func $nn (param $r (ref $t)) (result i32)
7 (block $l
8 (return (call_ref $t (br_on_null $l (local.get $r))))
9 )
10 (i32.const -1)
11 )
12 (func $n (param $r (ref null $t)) (result i32)
13 (block $l
14 (return (call_ref $t (br_on_null $l (local.get $r))))
15 )
16 (i32.const -1)
17 )
18
19 (elem func $f)
20 (func $f (result i32) (i32.const 7))
21
22 (func (export "nullable-null") (result i32) (call $n (ref.null $t)))
23 (func (export "nonnullable-f") (result i32) (call $nn (ref.func $f)))
24 (func (export "nullable-f") (result i32) (call $n (ref.func $f)))
25
26 (func (export "unreachable") (result i32)
27 (block $l
28 (return (call_ref $t (br_on_null $l (unreachable))))
29 )
30 (i32.const -1)
31 )
32 )
33
34 (assert_trap (invoke "unreachable") "unreachable")
35
36 (assert_return (invoke "nullable-null") (i32.const -1))
37 (assert_return (invoke "nonnullable-f") (i32.const 7))
38 (assert_return (invoke "nullable-f") (i32.const 7))
39
40 (module
41 (type $t (func))
42 (func (param $r (ref null $t)) (drop (br_on_null 0 (local.get $r))))
43 (func (param $r (ref null func)) (drop (br_on_null 0 (local.get $r))))
44 (func (param $r (ref null extern)) (drop (br_on_null 0 (local.get $r))))
45 )
46
47
48 (module
49 (type $t (func (param i32) (result i32)))
50 (elem func $f)
51 (func $f (param i32) (result i32) (i32.mul (local.get 0) (local.get 0)))
52
53 (func $a (param $n i32) (param $r (ref null $t)) (result i32)
54 (block $l (result i32)
55 (return (call_ref $t (br_on_null $l (local.get $n) (local.get $r))))
56 )
57 )
58
59 (func (export "args-null") (param $n i32) (result i32)
60 (call $a (local.get $n) (ref.null $t))
61 )
62 (func (export "args-f") (param $n i32) (result i32)
63 (call $a (local.get $n) (ref.func $f))
64 )
65 )
66
67 (assert_return (invoke "args-null" (i32.const 3)) (i32.const 3))
68 (assert_return (invoke "args-f" (i32.const 3)) (i32.const 9))