summaryrefslogtreecommitdiff
path: root/test/extra-unreachable.wast
blob: 7c9ed8814f86d8ec26a6f5bfaa61f25c8562fbb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
(module
  (type $ii (param i32) (result i32))
  (memory (shared 1 1))
  (table 0 funcref)
  (global $g (mut f32) (f32.const 0))
  (event $e (attr 0) (param i32))

  (func $foo (param i32) (result i32) (i32.const 0))

  (func $test_function_block
    ;; block, which has unreachable type, can be omitted here because it is the
    ;; only expression within a function. We emit an extra unreachable at the
    ;; end.
    (block
      (unreachable)
      (nop)
    )
  )

  (func $test
    ;; block has unreachable type. We emit an unreachable at the end of the
    ;; block and also outside the block too.
    (block
      (i32.eqz (unreachable))
    )

    ;; If an if's condition is unreachable, don't emit the if and emit an
    ;; unreachable instead.
    (if
      (unreachable)
      (nop)
      (nop)
    )

    ;; If an if is unreachable, i.e., the both sides are unreachable, we emit
    ;; an extra unreachable after the if.
    (if
      (i32.const 1)
      (unreachable)
      (unreachable)
    )

    ;; If a try is unreachable, i.e., both the 'try' and 'catch' bodies are
    ;; unreachable, we emit an extra unreachable after the try.
    (try
      (do
        (unreachable)
      )
      (catch
        (unreachable)
      )
    )

    ;; If a br_if/br_on_exn's type is unreachable, emit an extra unreachable
    ;; after it
    (block
      (br_if 0 (unreachable))
    )
    (drop
      (block (result i32)
        (br_on_exn 0 $e (unreachable))
      )
    )

    ;; If a br_table is not reachable, emit an unreachable instead
    (block $l
      (block $default
        (br_table $l $default
          (unreachable)
        )
      )
    )

    ;; For all tests below, when a value-returning expression is unreachable,
    ;; emit an unreachable instead of the operation, to prevent it from being
    ;; consumed by the next operation.
    ;;
    ;; Here global.set is used to consume the value. If an unreachable is not
    ;; emitted, the instruction itself will be consumed by global.set and will
    ;; result in a type validation failure, because it expects a f32 but gets an
    ;; i32. The reason we use global.set is the instruction does not return a
    ;; value, so it will be emitted even if its argument is unreachable.

    ;; call / call_indirect
    (global.set $g
      (call $foo (unreachable))
    )
    (global.set $g
      (call_indirect (type $ii) (unreachable))
    )

    ;; unary
    (global.set $g
      (i32.eqz (unreachable))
    )

    ;; binary
    (global.set $g
      (i32.add
        (unreachable)
        (i32.const 0)
      )
    )

    ;; select
    (global.set $g
      (select
        (unreachable)
        (i32.const 0)
        (i32.const 0)
      )
    )

    ;; load
    (global.set $g
      (i32.load (unreachable))
    )
    (global.set $g
      (i32.atomic.load (unreachable))
    )

    ;; atomic.rmw
    (global.set $g
      (i32.atomic.rmw.add
        (unreachable)
        (i32.const 0)
      )
    )

    ;; atomic.cmpxchg
    (global.set $g
      (i32.atomic.rmw.cmpxchg
        (unreachable)
        (i32.const 0)
        (i32.const 0)
      )
    )

    ;; atomic.wait
    (global.set $g
      (i32.atomic.wait
        (unreachable)
        (i32.const 0)
        (i64.const 0)
      )
    )

    ;; atomic.notify
    (global.set $g
      (atomic.notify
        (unreachable)
        (i32.const 0)
      )
    )

    ;; SIMD extract
    (global.set $g
      (i32x4.extract_lane 0
        (unreachable)
      )
    )

    ;; SIMD replace
    (global.set $g
      (i32x4.replace_lane 0
        (unreachable)
        (i32.const 0)
      )
    )

    ;; SIMD shuffle
    (global.set $g
      (v8x16.shuffle 0 17 2 19 4 21 6 23 8 25 10 27 12 29 14 31
        (unreachable)
        (unreachable)
      )
    )

    ;; SIMD bitselect
    (global.set $g
      (v128.bitselect
        (unreachable)
        (unreachable)
        (unreachable)
      )
    )

    ;; SIMD shift
    (global.set $g
      (i32x4.shl
        (unreachable)
        (i32.const 0)
      )
    )
  )
)