Debian Codegraph @

tests/cli/function-references/call_ref/br_on_non_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 (call_ref $t
8 (block $l (result (ref $t))
9 (br_on_non_null $l (local.get $r))
10 (return (i32.const -1))
11 )
12 )
13 )
14 (func $n (param $r (ref null $t)) (result i32)
15 (call_ref $t
16 (block $l (result (ref $t))
17 (br_on_non_null $l (local.get $r))
18 (return (i32.const -1))
19 )
20 )
21 )
22
23 (elem func $f)
24 (func $f (result i32) (i32.const 7))
25
26 (func (export "nullable-null") (result i32) (call $n (ref.null $t)))
27 (func (export "nonnullable-f") (result i32) (call $nn (ref.func $f)))
28 (func (export "nullable-f") (result i32) (call $n (ref.func $f)))
29
30 (func (export "unreachable") (result i32)
31 (block $l
32 (return (call_ref $t (br_on_null $l (unreachable))))
33 )
34 (i32.const -1)
35 )
36 )
37
38 (assert_trap (invoke "unreachable") "unreachable")
39
40 (assert_return (invoke "nullable-null") (i32.const -1))
41 (assert_return (invoke "nonnullable-f") (i32.const 7))
42 (assert_return (invoke "nullable-f") (i32.const 7))
43
44 (module
45 (type $t (func))
46 (func (param $r (ref null $t)) (drop (block (result (ref $t)) (br_on_non_null 0 (local.get $r)) (unreachable))))
47 (func (param $r (ref null func)) (drop (block (result (ref func)) (br_on_non_null 0 (local.get $r)) (unreachable))))
48 (func (param $r (ref null extern)) (drop (block (result (ref extern)) (br_on_non_null 0 (local.get $r)) (unreachable))))
49 )
50
51
52 (module
53 (type $t (func (param i32) (result i32)))
54 (elem func $f)
55 (func $f (param i32) (result i32) (i32.mul (local.get 0) (local.get 0)))
56
57 (func $a (param $n i32) (param $r (ref null $t)) (result i32)
58 (call_ref $t
59 (block $l (result i32 (ref $t))
60 (return (br_on_non_null $l (local.get $n) (local.get $r)))
61 )
62 )
63 )
64
65 (func (export "args-null") (param $n i32) (result i32)
66 (call $a (local.get $n) (ref.null $t))
67 )
68 (func (export "args-f") (param $n i32) (result i32)
69 (call $a (local.get $n) (ref.func $f))
70 )
71 )
72
73 (assert_return (invoke "args-null" (i32.const 3)) (i32.const 3))
74 (assert_return (invoke "args-f" (i32.const 3)) (i32.const 9))