Debian Codegraph @

internal/integration_test/spectest/v2/testdata/if.wast

raw
1 ;; Test `if` operator
2
3 (module
4 ;; Auxiliary definition
5 (memory 1)
6
7 (func $dummy)
8
9 (func (export "empty") (param i32)
10 (if (local.get 0) (then))
11 (if (local.get 0) (then) (else))
12 (if $l (local.get 0) (then))
13 (if $l (local.get 0) (then) (else))
14 )
15
16 (func (export "singular") (param i32) (result i32)
17 (if (local.get 0) (then (nop)))
18 (if (local.get 0) (then (nop)) (else (nop)))
19 (if (result i32) (local.get 0) (then (i32.const 7)) (else (i32.const 8)))
20 )
21
22 (func (export "multi") (param i32) (result i32 i32)
23 (if (local.get 0) (then (call $dummy) (call $dummy) (call $dummy)))
24 (if (local.get 0) (then) (else (call $dummy) (call $dummy) (call $dummy)))
25 (if (result i32) (local.get 0)
26 (then (call $dummy) (call $dummy) (i32.const 8) (call $dummy))
27 (else (call $dummy) (call $dummy) (i32.const 9) (call $dummy))
28 )
29 (if (result i32 i64 i32) (local.get 0)
30 (then
31 (call $dummy) (call $dummy) (i32.const 1) (call $dummy)
32 (call $dummy) (call $dummy) (i64.const 2) (call $dummy)
33 (call $dummy) (call $dummy) (i32.const 3) (call $dummy)
34 )
35 (else
36 (call $dummy) (call $dummy) (i32.const -1) (call $dummy)
37 (call $dummy) (call $dummy) (i64.const -2) (call $dummy)
38 (call $dummy) (call $dummy) (i32.const -3) (call $dummy)
39 )
40 )
41 (drop) (drop)
42 )
43
44 (func (export "nested") (param i32 i32) (result i32)
45 (if (result i32) (local.get 0)
46 (then
47 (if (local.get 1) (then (call $dummy) (block) (nop)))
48 (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
49 (if (result i32) (local.get 1)
50 (then (call $dummy) (i32.const 9))
51 (else (call $dummy) (i32.const 10))
52 )
53 )
54 (else
55 (if (local.get 1) (then (call $dummy) (block) (nop)))
56 (if (local.get 1) (then) (else (call $dummy) (block) (nop)))
57 (if (result i32) (local.get 1)
58 (then (call $dummy) (i32.const 10))
59 (else (call $dummy) (i32.const 11))
60 )
61 )
62 )
63 )
64
65 (func (export "as-select-first") (param i32) (result i32)
66 (select
67 (if (result i32) (local.get 0)
68 (then (call $dummy) (i32.const 1))
69 (else (call $dummy) (i32.const 0))
70 )
71 (i32.const 2) (i32.const 3)
72 )
73 )
74 (func (export "as-select-mid") (param i32) (result i32)
75 (select
76 (i32.const 2)
77 (if (result i32) (local.get 0)
78 (then (call $dummy) (i32.const 1))
79 (else (call $dummy) (i32.const 0))
80 )
81 (i32.const 3)
82 )
83 )
84 (func (export "as-select-last") (param i32) (result i32)
85 (select
86 (i32.const 2) (i32.const 3)
87 (if (result i32) (local.get 0)
88 (then (call $dummy) (i32.const 1))
89 (else (call $dummy) (i32.const 0))
90 )
91 )
92 )
93
94 (func (export "as-loop-first") (param i32) (result i32)
95 (loop (result i32)
96 (if (result i32) (local.get 0)
97 (then (call $dummy) (i32.const 1))
98 (else (call $dummy) (i32.const 0))
99 )
100 (call $dummy) (call $dummy)
101 )
102 )
103 (func (export "as-loop-mid") (param i32) (result i32)
104 (loop (result i32)
105 (call $dummy)
106 (if (result i32) (local.get 0)
107 (then (call $dummy) (i32.const 1))
108 (else (call $dummy) (i32.const 0))
109 )
110 (call $dummy)
111 )
112 )
113 (func (export "as-loop-last") (param i32) (result i32)
114 (loop (result i32)
115 (call $dummy) (call $dummy)
116 (if (result i32) (local.get 0)
117 (then (call $dummy) (i32.const 1))
118 (else (call $dummy) (i32.const 0))
119 )
120 )
121 )
122
123 (func (export "as-if-condition") (param i32) (result i32)
124 (if (result i32)
125 (if (result i32) (local.get 0)
126 (then (i32.const 1)) (else (i32.const 0))
127 )
128 (then (call $dummy) (i32.const 2))
129 (else (call $dummy) (i32.const 3))
130 )
131 )
132
133 (func (export "as-br_if-first") (param i32) (result i32)
134 (block (result i32)
135 (br_if 0
136 (if (result i32) (local.get 0)
137 (then (call $dummy) (i32.const 1))
138 (else (call $dummy) (i32.const 0))
139 )
140 (i32.const 2)
141 )
142 (return (i32.const 3))
143 )
144 )
145 (func (export "as-br_if-last") (param i32) (result i32)
146 (block (result i32)
147 (br_if 0
148 (i32.const 2)
149 (if (result i32) (local.get 0)
150 (then (call $dummy) (i32.const 1))
151 (else (call $dummy) (i32.const 0))
152 )
153 )
154 (return (i32.const 3))
155 )
156 )
157
158 (func (export "as-br_table-first") (param i32) (result i32)
159 (block (result i32)
160 (if (result i32) (local.get 0)
161 (then (call $dummy) (i32.const 1))
162 (else (call $dummy) (i32.const 0))
163 )
164 (i32.const 2)
165 (br_table 0 0)
166 )
167 )
168 (func (export "as-br_table-last") (param i32) (result i32)
169 (block (result i32)
170 (i32.const 2)
171 (if (result i32) (local.get 0)
172 (then (call $dummy) (i32.const 1))
173 (else (call $dummy) (i32.const 0))
174 )
175 (br_table 0 0)
176 )
177 )
178
179 (func $func (param i32 i32) (result i32) (local.get 0))
180 (type $check (func (param i32 i32) (result i32)))
181 (table funcref (elem $func))
182 (func (export "as-call_indirect-first") (param i32) (result i32)
183 (block (result i32)
184 (call_indirect (type $check)
185 (if (result i32) (local.get 0)
186 (then (call $dummy) (i32.const 1))
187 (else (call $dummy) (i32.const 0))
188 )
189 (i32.const 2) (i32.const 0)
190 )
191 )
192 )
193 (func (export "as-call_indirect-mid") (param i32) (result i32)
194 (block (result i32)
195 (call_indirect (type $check)
196 (i32.const 2)
197 (if (result i32) (local.get 0)
198 (then (call $dummy) (i32.const 1))
199 (else (call $dummy) (i32.const 0))
200 )
201 (i32.const 0)
202 )
203 )
204 )
205 (func (export "as-call_indirect-last") (param i32) (result i32)
206 (block (result i32)
207 (call_indirect (type $check)
208 (i32.const 2) (i32.const 0)
209 (if (result i32) (local.get 0)
210 (then (call $dummy) (i32.const 1))
211 (else (call $dummy) (i32.const 0))
212 )
213 )
214 )
215 )
216
217 (func (export "as-store-first") (param i32)
218 (if (result i32) (local.get 0)
219 (then (call $dummy) (i32.const 1))
220 (else (call $dummy) (i32.const 0))
221 )
222 (i32.const 2)
223 (i32.store)
224 )
225 (func (export "as-store-last") (param i32)
226 (i32.const 2)
227 (if (result i32) (local.get 0)
228 (then (call $dummy) (i32.const 1))
229 (else (call $dummy) (i32.const 0))
230 )
231 (i32.store)
232 )
233
234 (func (export "as-memory.grow-value") (param i32) (result i32)
235 (memory.grow
236 (if (result i32) (local.get 0)
237 (then (i32.const 1))
238 (else (i32.const 0))
239 )
240 )
241 )
242
243 (func $f (param i32) (result i32) (local.get 0))
244
245 (func (export "as-call-value") (param i32) (result i32)
246 (call $f
247 (if (result i32) (local.get 0)
248 (then (i32.const 1))
249 (else (i32.const 0))
250 )
251 )
252 )
253 (func (export "as-return-value") (param i32) (result i32)
254 (if (result i32) (local.get 0)
255 (then (i32.const 1))
256 (else (i32.const 0)))
257 (return)
258 )
259 (func (export "as-drop-operand") (param i32)
260 (drop
261 (if (result i32) (local.get 0)
262 (then (i32.const 1))
263 (else (i32.const 0))
264 )
265 )
266 )
267 (func (export "as-br-value") (param i32) (result i32)
268 (block (result i32)
269 (br 0
270 (if (result i32) (local.get 0)
271 (then (i32.const 1))
272 (else (i32.const 0))
273 )
274 )
275 )
276 )
277 (func (export "as-local.set-value") (param i32) (result i32)
278 (local i32)
279 (local.set 0
280 (if (result i32) (local.get 0)
281 (then (i32.const 1))
282 (else (i32.const 0))
283 )
284 )
285 (local.get 0)
286 )
287 (func (export "as-local.tee-value") (param i32) (result i32)
288 (local.tee 0
289 (if (result i32) (local.get 0)
290 (then (i32.const 1))
291 (else (i32.const 0))
292 )
293 )
294 )
295 (global $a (mut i32) (i32.const 10))
296 (func (export "as-global.set-value") (param i32) (result i32)
297 (global.set $a
298 (if (result i32) (local.get 0)
299 (then (i32.const 1))
300 (else (i32.const 0))
301 )
302 ) (global.get $a)
303 )
304 (func (export "as-load-operand") (param i32) (result i32)
305 (i32.load
306 (if (result i32) (local.get 0)
307 (then (i32.const 11))
308 (else (i32.const 10))
309 )
310 )
311 )
312
313 (func (export "as-unary-operand") (param i32) (result i32)
314 (i32.ctz
315 (if (result i32) (local.get 0)
316 (then (call $dummy) (i32.const 13))
317 (else (call $dummy) (i32.const -13))
318 )
319 )
320 )
321 (func (export "as-binary-operand") (param i32 i32) (result i32)
322 (i32.mul
323 (if (result i32) (local.get 0)
324 (then (call $dummy) (i32.const 3))
325 (else (call $dummy) (i32.const -3))
326 )
327 (if (result i32) (local.get 1)
328 (then (call $dummy) (i32.const 4))
329 (else (call $dummy) (i32.const -5))
330 )
331 )
332 )
333 (func (export "as-test-operand") (param i32) (result i32)
334 (i32.eqz
335 (if (result i32) (local.get 0)
336 (then (call $dummy) (i32.const 13))
337 (else (call $dummy) (i32.const 0))
338 )
339 )
340 )
341 (func (export "as-compare-operand") (param i32 i32) (result i32)
342 (f32.gt
343 (if (result f32) (local.get 0)
344 (then (call $dummy) (f32.const 3))
345 (else (call $dummy) (f32.const -3))
346 )
347 (if (result f32) (local.get 1)
348 (then (call $dummy) (f32.const 4))
349 (else (call $dummy) (f32.const -4))
350 )
351 )
352 )
353 (func (export "as-binary-operands") (param i32) (result i32)
354 (i32.mul
355 (if (result i32 i32) (local.get 0)
356 (then (call $dummy) (i32.const 3) (call $dummy) (i32.const 4))
357 (else (call $dummy) (i32.const 3) (call $dummy) (i32.const -4))
358 )
359 )
360 )
361 (func (export "as-compare-operands") (param i32) (result i32)
362 (f32.gt
363 (if (result f32 f32) (local.get 0)
364 (then (call $dummy) (f32.const 3) (call $dummy) (f32.const 3))
365 (else (call $dummy) (f32.const -2) (call $dummy) (f32.const -3))
366 )
367 )
368 )
369 (func (export "as-mixed-operands") (param i32) (result i32)
370 (if (result i32 i32) (local.get 0)
371 (then (call $dummy) (i32.const 3) (call $dummy) (i32.const 4))
372 (else (call $dummy) (i32.const -3) (call $dummy) (i32.const -4))
373 )
374 (i32.const 5)
375 (i32.add)
376 (i32.mul)
377 )
378
379 (func (export "break-bare") (result i32)
380 (if (i32.const 1) (then (br 0) (unreachable)))
381 (if (i32.const 1) (then (br 0) (unreachable)) (else (unreachable)))
382 (if (i32.const 0) (then (unreachable)) (else (br 0) (unreachable)))
383 (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)))
384 (if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)) (else (unreachable)))
385 (if (i32.const 0) (then (unreachable)) (else (br_if 0 (i32.const 1)) (unreachable)))
386 (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)))
387 (if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)) (else (unreachable)))
388 (if (i32.const 0) (then (unreachable)) (else (br_table 0 (i32.const 0)) (unreachable)))
389 (i32.const 19)
390 )
391
392 (func (export "break-value") (param i32) (result i32)
393 (if (result i32) (local.get 0)
394 (then (br 0 (i32.const 18)) (i32.const 19))
395 (else (br 0 (i32.const 21)) (i32.const 20))
396 )
397 )
398 (func (export "break-multi-value") (param i32) (result i32 i32 i64)
399 (if (result i32 i32 i64) (local.get 0)
400 (then
401 (br 0 (i32.const 18) (i32.const -18) (i64.const 18))
402 (i32.const 19) (i32.const -19) (i64.const 19)
403 )
404 (else
405 (br 0 (i32.const -18) (i32.const 18) (i64.const -18))
406 (i32.const -19) (i32.const 19) (i64.const -19)
407 )
408 )
409 )
410
411 (func (export "param") (param i32) (result i32)
412 (i32.const 1)
413 (if (param i32) (result i32) (local.get 0)
414 (then (i32.const 2) (i32.add))
415 (else (i32.const -2) (i32.add))
416 )
417 )
418 (func (export "params") (param i32) (result i32)
419 (i32.const 1)
420 (i32.const 2)
421 (if (param i32 i32) (result i32) (local.get 0)
422 (then (i32.add))
423 (else (i32.sub))
424 )
425 )
426 (func (export "params-id") (param i32) (result i32)
427 (i32.const 1)
428 (i32.const 2)
429 (if (param i32 i32) (result i32 i32) (local.get 0) (then))
430 (i32.add)
431 )
432 (func (export "param-break") (param i32) (result i32)
433 (i32.const 1)
434 (if (param i32) (result i32) (local.get 0)
435 (then (i32.const 2) (i32.add) (br 0))
436 (else (i32.const -2) (i32.add) (br 0))
437 )
438 )
439 (func (export "params-break") (param i32) (result i32)
440 (i32.const 1)
441 (i32.const 2)
442 (if (param i32 i32) (result i32) (local.get 0)
443 (then (i32.add) (br 0))
444 (else (i32.sub) (br 0))
445 )
446 )
447 (func (export "params-id-break") (param i32) (result i32)
448 (i32.const 1)
449 (i32.const 2)
450 (if (param i32 i32) (result i32 i32) (local.get 0) (then (br 0)))
451 (i32.add)
452 )
453
454 (func (export "effects") (param i32) (result i32)
455 (local i32)
456 (if
457 (block (result i32) (local.set 1 (i32.const 1)) (local.get 0))
458 (then
459 (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
460 (local.set 1 (i32.sub (local.get 1) (i32.const 5)))
461 (local.set 1 (i32.mul (local.get 1) (i32.const 7)))
462 (br 0)
463 (local.set 1 (i32.mul (local.get 1) (i32.const 100)))
464 )
465 (else
466 (local.set 1 (i32.mul (local.get 1) (i32.const 5)))
467 (local.set 1 (i32.sub (local.get 1) (i32.const 7)))
468 (local.set 1 (i32.mul (local.get 1) (i32.const 3)))
469 (br 0)
470 (local.set 1 (i32.mul (local.get 1) (i32.const 1000)))
471 )
472 )
473 (local.get 1)
474 )
475
476 ;; Examples
477
478 (func $add64_u_with_carry (export "add64_u_with_carry")
479 (param $i i64) (param $j i64) (param $c i32) (result i64 i32)
480 (local $k i64)
481 (local.set $k
482 (i64.add
483 (i64.add (local.get $i) (local.get $j))
484 (i64.extend_i32_u (local.get $c))
485 )
486 )
487 (return (local.get $k) (i64.lt_u (local.get $k) (local.get $i)))
488 )
489
490 (func $add64_u_saturated (export "add64_u_saturated")
491 (param i64 i64) (result i64)
492 (call $add64_u_with_carry (local.get 0) (local.get 1) (i32.const 0))
493 (if (param i64) (result i64)
494 (then (drop) (i64.const -1))
495 )
496 )
497
498 ;; Block signature syntax
499
500 (type $block-sig-1 (func))
501 (type $block-sig-2 (func (result i32)))
502 (type $block-sig-3 (func (param $x i32)))
503 (type $block-sig-4 (func (param i32 f64 i32) (result i32 f64 i32)))
504
505 (func (export "type-use")
506 (if (type $block-sig-1) (i32.const 1) (then))
507 (if (type $block-sig-2) (i32.const 1)
508 (then (i32.const 0)) (else (i32.const 2))
509 )
510 (if (type $block-sig-3) (i32.const 1) (then (drop)) (else (drop)))
511 (i32.const 0) (f64.const 0) (i32.const 0)
512 (if (type $block-sig-4) (i32.const 1) (then))
513 (drop) (drop) (drop)
514 (if (type $block-sig-2) (result i32) (i32.const 1)
515 (then (i32.const 0)) (else (i32.const 2))
516 )
517 (if (type $block-sig-3) (param i32) (i32.const 1)
518 (then (drop)) (else (drop))
519 )
520 (i32.const 0) (f64.const 0) (i32.const 0)
521 (if (type $block-sig-4)
522 (param i32) (param f64 i32) (result i32 f64) (result i32)
523 (i32.const 1) (then)
524 )
525 (drop) (drop) (drop)
526 )
527
528 ;; Atypical folded condition syntax
529
530 (func (export "atypical-condition")
531 i32.const 0
532 (if (then) (else))
533 (if (i32.const 1) (i32.eqz) (then) (else))
534 )
535 )
536
537 (assert_return (invoke "empty" (i32.const 0)))
538 (assert_return (invoke "empty" (i32.const 1)))
539 (assert_return (invoke "empty" (i32.const 100)))
540 (assert_return (invoke "empty" (i32.const -2)))
541
542 (assert_return (invoke "singular" (i32.const 0)) (i32.const 8))
543 (assert_return (invoke "singular" (i32.const 1)) (i32.const 7))
544 (assert_return (invoke "singular" (i32.const 10)) (i32.const 7))
545 (assert_return (invoke "singular" (i32.const -10)) (i32.const 7))
546
547 (assert_return (invoke "multi" (i32.const 0)) (i32.const 9) (i32.const -1))
548 (assert_return (invoke "multi" (i32.const 1)) (i32.const 8) (i32.const 1))
549 (assert_return (invoke "multi" (i32.const 13)) (i32.const 8) (i32.const 1))
550 (assert_return (invoke "multi" (i32.const -5)) (i32.const 8) (i32.const 1))
551
552 (assert_return (invoke "nested" (i32.const 0) (i32.const 0)) (i32.const 11))
553 (assert_return (invoke "nested" (i32.const 1) (i32.const 0)) (i32.const 10))
554 (assert_return (invoke "nested" (i32.const 0) (i32.const 1)) (i32.const 10))
555 (assert_return (invoke "nested" (i32.const 3) (i32.const 2)) (i32.const 9))
556 (assert_return (invoke "nested" (i32.const 0) (i32.const -100)) (i32.const 10))
557 (assert_return (invoke "nested" (i32.const 10) (i32.const 10)) (i32.const 9))
558 (assert_return (invoke "nested" (i32.const 0) (i32.const -1)) (i32.const 10))
559 (assert_return (invoke "nested" (i32.const -111) (i32.const -2)) (i32.const 9))
560
561 (assert_return (invoke "as-select-first" (i32.const 0)) (i32.const 0))
562 (assert_return (invoke "as-select-first" (i32.const 1)) (i32.const 1))
563 (assert_return (invoke "as-select-mid" (i32.const 0)) (i32.const 2))
564 (assert_return (invoke "as-select-mid" (i32.const 1)) (i32.const 2))
565 (assert_return (invoke "as-select-last" (i32.const 0)) (i32.const 3))
566 (assert_return (invoke "as-select-last" (i32.const 1)) (i32.const 2))
567
568 (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 0))
569 (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 1))
570 (assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 0))
571 (assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 1))
572 (assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 0))
573 (assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 1))
574
575 (assert_return (invoke "as-if-condition" (i32.const 0)) (i32.const 3))
576 (assert_return (invoke "as-if-condition" (i32.const 1)) (i32.const 2))
577
578 (assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 0))
579 (assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 1))
580 (assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 3))
581 (assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2))
582
583 (assert_return (invoke "as-br_table-first" (i32.const 0)) (i32.const 0))
584 (assert_return (invoke "as-br_table-first" (i32.const 1)) (i32.const 1))
585 (assert_return (invoke "as-br_table-last" (i32.const 0)) (i32.const 2))
586 (assert_return (invoke "as-br_table-last" (i32.const 1)) (i32.const 2))
587
588 (assert_return (invoke "as-call_indirect-first" (i32.const 0)) (i32.const 0))
589 (assert_return (invoke "as-call_indirect-first" (i32.const 1)) (i32.const 1))
590 (assert_return (invoke "as-call_indirect-mid" (i32.const 0)) (i32.const 2))
591 (assert_return (invoke "as-call_indirect-mid" (i32.const 1)) (i32.const 2))
592 (assert_return (invoke "as-call_indirect-last" (i32.const 0)) (i32.const 2))
593 (assert_trap (invoke "as-call_indirect-last" (i32.const 1)) "undefined element")
594
595 (assert_return (invoke "as-store-first" (i32.const 0)))
596 (assert_return (invoke "as-store-first" (i32.const 1)))
597 (assert_return (invoke "as-store-last" (i32.const 0)))
598 (assert_return (invoke "as-store-last" (i32.const 1)))
599
600 (assert_return (invoke "as-memory.grow-value" (i32.const 0)) (i32.const 1))
601 (assert_return (invoke "as-memory.grow-value" (i32.const 1)) (i32.const 1))
602
603 (assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 0))
604 (assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1))
605
606 (assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0))
607 (assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1))
608
609 (assert_return (invoke "as-drop-operand" (i32.const 0)))
610 (assert_return (invoke "as-drop-operand" (i32.const 1)))
611
612 (assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 0))
613 (assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1))
614
615 (assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const 0))
616 (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 1))
617
618 (assert_return (invoke "as-local.tee-value" (i32.const 0)) (i32.const 0))
619 (assert_return (invoke "as-local.tee-value" (i32.const 1)) (i32.const 1))
620
621 (assert_return (invoke "as-global.set-value" (i32.const 0)) (i32.const 0))
622 (assert_return (invoke "as-global.set-value" (i32.const 1)) (i32.const 1))
623
624 (assert_return (invoke "as-load-operand" (i32.const 0)) (i32.const 0))
625 (assert_return (invoke "as-load-operand" (i32.const 1)) (i32.const 0))
626
627 (assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0))
628 (assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 0))
629 (assert_return (invoke "as-unary-operand" (i32.const -1)) (i32.const 0))
630
631 (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 0)) (i32.const 15))
632 (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 1)) (i32.const -12))
633 (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 0)) (i32.const -15))
634 (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 1)) (i32.const 12))
635
636 (assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 1))
637 (assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 0))
638
639 (assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 0)) (i32.const 1))
640 (assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 1)) (i32.const 0))
641 (assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 0)) (i32.const 1))
642 (assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 1)) (i32.const 0))
643
644 (assert_return (invoke "as-binary-operands" (i32.const 0)) (i32.const -12))
645 (assert_return (invoke "as-binary-operands" (i32.const 1)) (i32.const 12))
646
647 (assert_return (invoke "as-compare-operands" (i32.const 0)) (i32.const 1))
648 (assert_return (invoke "as-compare-operands" (i32.const 1)) (i32.const 0))
649
650 (assert_return (invoke "as-mixed-operands" (i32.const 0)) (i32.const -3))
651 (assert_return (invoke "as-mixed-operands" (i32.const 1)) (i32.const 27))
652
653 (assert_return (invoke "break-bare") (i32.const 19))
654 (assert_return (invoke "break-value" (i32.const 1)) (i32.const 18))
655 (assert_return (invoke "break-value" (i32.const 0)) (i32.const 21))
656 (assert_return (invoke "break-multi-value" (i32.const 0))
657 (i32.const -18) (i32.const 18) (i64.const -18)
658 )
659 (assert_return (invoke "break-multi-value" (i32.const 1))
660 (i32.const 18) (i32.const -18) (i64.const 18)
661 )
662
663 (assert_return (invoke "param" (i32.const 0)) (i32.const -1))
664 (assert_return (invoke "param" (i32.const 1)) (i32.const 3))
665 (assert_return (invoke "params" (i32.const 0)) (i32.const -1))
666 (assert_return (invoke "params" (i32.const 1)) (i32.const 3))
667 (assert_return (invoke "params-id" (i32.const 0)) (i32.const 3))
668 (assert_return (invoke "params-id" (i32.const 1)) (i32.const 3))
669 (assert_return (invoke "param-break" (i32.const 0)) (i32.const -1))
670 (assert_return (invoke "param-break" (i32.const 1)) (i32.const 3))
671 (assert_return (invoke "params-break" (i32.const 0)) (i32.const -1))
672 (assert_return (invoke "params-break" (i32.const 1)) (i32.const 3))
673 (assert_return (invoke "params-id-break" (i32.const 0)) (i32.const 3))
674 (assert_return (invoke "params-id-break" (i32.const 1)) (i32.const 3))
675
676 (assert_return (invoke "effects" (i32.const 1)) (i32.const -14))
677 (assert_return (invoke "effects" (i32.const 0)) (i32.const -6))
678
679 (assert_return
680 (invoke "add64_u_with_carry" (i64.const 0) (i64.const 0) (i32.const 0))
681 (i64.const 0) (i32.const 0)
682 )
683 (assert_return
684 (invoke "add64_u_with_carry" (i64.const 100) (i64.const 124) (i32.const 0))
685 (i64.const 224) (i32.const 0)
686 )
687 (assert_return
688 (invoke "add64_u_with_carry" (i64.const -1) (i64.const 0) (i32.const 0))
689 (i64.const -1) (i32.const 0)
690 )
691 (assert_return
692 (invoke "add64_u_with_carry" (i64.const -1) (i64.const 1) (i32.const 0))
693 (i64.const 0) (i32.const 1)
694 )
695 (assert_return
696 (invoke "add64_u_with_carry" (i64.const -1) (i64.const -1) (i32.const 0))
697 (i64.const -2) (i32.const 1)
698 )
699 (assert_return
700 (invoke "add64_u_with_carry" (i64.const -1) (i64.const 0) (i32.const 1))
701 (i64.const 0) (i32.const 1)
702 )
703 (assert_return
704 (invoke "add64_u_with_carry" (i64.const -1) (i64.const 1) (i32.const 1))
705 (i64.const 1) (i32.const 1)
706 )
707 (assert_return
708 (invoke "add64_u_with_carry" (i64.const 0x8000000000000000) (i64.const 0x8000000000000000) (i32.const 0))
709 (i64.const 0) (i32.const 1)
710 )
711
712 (assert_return
713 (invoke "add64_u_saturated" (i64.const 0) (i64.const 0)) (i64.const 0)
714 )
715 (assert_return
716 (invoke "add64_u_saturated" (i64.const 1230) (i64.const 23)) (i64.const 1253)
717 )
718 (assert_return
719 (invoke "add64_u_saturated" (i64.const -1) (i64.const 0)) (i64.const -1)
720 )
721 (assert_return
722 (invoke "add64_u_saturated" (i64.const -1) (i64.const 1)) (i64.const -1)
723 )
724 (assert_return
725 (invoke "add64_u_saturated" (i64.const -1) (i64.const -1)) (i64.const -1)
726 )
727 (assert_return
728 (invoke "add64_u_saturated" (i64.const 0x8000000000000000) (i64.const 0x8000000000000000)) (i64.const -1)
729 )
730
731 (assert_return (invoke "type-use"))
732
733 (assert_return (invoke "atypical-condition"))
734
735 (assert_malformed
736 (module quote
737 "(type $sig (func (param i32) (result i32)))"
738 "(func (i32.const 0)"
739 " (if (type $sig) (result i32) (param i32) (i32.const 1) (then))"
740 ")"
741 )
742 "unexpected token"
743 )
744 (assert_malformed
745 (module quote
746 "(type $sig (func (param i32) (result i32)))"
747 "(func (i32.const 0)"
748 " (if (param i32) (type $sig) (result i32) (i32.const 1) (then))"
749 ")"
750 )
751 "unexpected token"
752 )
753 (assert_malformed
754 (module quote
755 "(type $sig (func (param i32) (result i32)))"
756 "(func (i32.const 0)"
757 " (if (param i32) (result i32) (type $sig) (i32.const 1) (then))"
758 ")"
759 )
760 "unexpected token"
761 )
762 (assert_malformed
763 (module quote
764 "(type $sig (func (param i32) (result i32)))"
765 "(func (i32.const 0)"
766 " (if (result i32) (type $sig) (param i32) (i32.const 1) (then))"
767 ")"
768 )
769 "unexpected token"
770 )
771 (assert_malformed
772 (module quote
773 "(type $sig (func (param i32) (result i32)))"
774 "(func (i32.const 0)"
775 " (if (result i32) (param i32) (type $sig) (i32.const 1) (then))"
776 ")"
777 )
778 "unexpected token"
779 )
780 (assert_malformed
781 (module quote
782 "(func (i32.const 0) (if (result i32) (param i32) (i32.const 1) (then)))"
783 )
784 "unexpected token"
785 )
786
787 (assert_malformed
788 (module quote
789 "(func (i32.const 0) (i32.const 1)"
790 " (if (param $x i32) (then (drop)) (else (drop)))"
791 ")"
792 )
793 "unexpected token"
794 )
795 (assert_malformed
796 (module quote
797 "(type $sig (func))"
798 "(func (i32.const 1)"
799 " (if (type $sig) (result i32) (then (i32.const 0)) (else (i32.const 2)))"
800 " (unreachable)"
801 ")"
802 )
803 "inline function type"
804 )
805 (assert_malformed
806 (module quote
807 "(type $sig (func (param i32) (result i32)))"
808 "(func (i32.const 1)"
809 " (if (type $sig) (result i32) (then (i32.const 0)) (else (i32.const 2)))"
810 " (unreachable)"
811 ")"
812 )
813 "inline function type"
814 )
815 (assert_malformed
816 (module quote
817 "(type $sig (func (param i32) (result i32)))"
818 "(func (i32.const 0) (i32.const 1)"
819 " (if (type $sig) (param i32) (then (drop)) (else (drop)))"
820 " (unreachable)"
821 ")"
822 )
823 "inline function type"
824 )
825 (assert_malformed
826 (module quote
827 "(type $sig (func (param i32 i32) (result i32)))"
828 "(func (i32.const 0) (i32.const 1)"
829 " (if (type $sig) (param i32) (result i32) (then)) (unreachable)"
830 ")"
831 )
832 "inline function type"
833 )
834
835 (assert_invalid
836 (module
837 (type $sig (func))
838 (func (i32.const 1) (if (type $sig) (i32.const 0) (then)))
839 )
840 "type mismatch"
841 )
842
843 (assert_invalid
844 (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then))))
845 "type mismatch"
846 )
847 (assert_invalid
848 (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then))))
849 "type mismatch"
850 )
851 (assert_invalid
852 (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then))))
853 "type mismatch"
854 )
855 (assert_invalid
856 (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then))))
857 "type mismatch"
858 )
859
860 (assert_invalid
861 (module (func $type-empty-i32 (result i32) (if (i32.const 0) (then) (else))))
862 "type mismatch"
863 )
864 (assert_invalid
865 (module (func $type-empty-i64 (result i64) (if (i32.const 0) (then) (else))))
866 "type mismatch"
867 )
868 (assert_invalid
869 (module (func $type-empty-f32 (result f32) (if (i32.const 0) (then) (else))))
870 "type mismatch"
871 )
872 (assert_invalid
873 (module (func $type-empty-f64 (result f64) (if (i32.const 0) (then) (else))))
874 "type mismatch"
875 )
876
877 (assert_invalid
878 (module (func $type-then-value-num-vs-void
879 (if (i32.const 1) (then (i32.const 1)))
880 ))
881 "type mismatch"
882 )
883 (assert_invalid
884 (module (func $type-then-value-num-vs-void-else
885 (if (i32.const 1) (then (i32.const 1)) (else))
886 ))
887 "type mismatch"
888 )
889 (assert_invalid
890 (module (func $type-else-value-num-vs-void
891 (if (i32.const 1) (then) (else (i32.const 1)))
892 ))
893 "type mismatch"
894 )
895 (assert_invalid
896 (module (func $type-both-value-num-vs-void
897 (if (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
898 ))
899 "type mismatch"
900 )
901
902 (assert_invalid
903 (module (func $type-then-value-nums-vs-void
904 (if (i32.const 1) (then (i32.const 1) (i32.const 2)))
905 ))
906 "type mismatch"
907 )
908 (assert_invalid
909 (module (func $type-then-value-nums-vs-void-else
910 (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else))
911 ))
912 "type mismatch"
913 )
914 (assert_invalid
915 (module (func $type-else-value-nums-vs-void
916 (if (i32.const 1) (then) (else (i32.const 1) (i32.const 2)))
917 ))
918 "type mismatch"
919 )
920 (assert_invalid
921 (module (func $type-both-value-nums-vs-void
922 (if (i32.const 1) (then (i32.const 1) (i32.const 2)) (else (i32.const 2) (i32.const 1)))
923 ))
924 "type mismatch"
925 )
926
927 (assert_invalid
928 (module (func $type-then-value-empty-vs-num (result i32)
929 (if (result i32) (i32.const 1) (then) (else (i32.const 0)))
930 ))
931 "type mismatch"
932 )
933 (assert_invalid
934 (module (func $type-else-value-empty-vs-num (result i32)
935 (if (result i32) (i32.const 1) (then (i32.const 0)) (else))
936 ))
937 "type mismatch"
938 )
939 (assert_invalid
940 (module (func $type-both-value-empty-vs-num (result i32)
941 (if (result i32) (i32.const 1) (then) (else))
942 ))
943 "type mismatch"
944 )
945
946 (assert_invalid
947 (module (func $type-then-value-empty-vs-nums (result i32 i32)
948 (if (result i32 i32) (i32.const 1) (then) (else (i32.const 0) (i32.const 2)))
949 ))
950 "type mismatch"
951 )
952 (assert_invalid
953 (module (func $type-else-value-empty-vs-nums (result i32 i32)
954 (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 1)) (else))
955 ))
956 "type mismatch"
957 )
958 (assert_invalid
959 (module (func $type-both-value-empty-vs-nums (result i32 i32)
960 (if (result i32 i32) (i32.const 1) (then) (else))
961 ))
962 "type mismatch"
963 )
964
965 (assert_invalid
966 (module (func $type-no-else-vs-num (result i32)
967 (if (result i32) (i32.const 1) (then (i32.const 1)))
968 ))
969 "type mismatch"
970 )
971 (assert_invalid
972 (module (func $type-no-else-vs-nums (result i32 i32)
973 (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)))
974 ))
975 "type mismatch"
976 )
977
978 (assert_invalid
979 (module (func $type-then-value-void-vs-num (result i32)
980 (if (result i32) (i32.const 1) (then (nop)) (else (i32.const 0)))
981 ))
982 "type mismatch"
983 )
984 (assert_invalid
985 (module (func $type-else-value-void-vs-num (result i32)
986 (if (result i32) (i32.const 1) (then (i32.const 0)) (else (nop)))
987 ))
988 "type mismatch"
989 )
990 (assert_invalid
991 (module (func $type-both-value-void-vs-num (result i32)
992 (if (result i32) (i32.const 1) (then (nop)) (else (nop)))
993 ))
994 "type mismatch"
995 )
996
997 (assert_invalid
998 (module (func $type-then-value-void-vs-nums (result i32 i32)
999 (if (result i32 i32) (i32.const 1) (then (nop)) (else (i32.const 0) (i32.const 0)))
1000 ))
1001 "type mismatch"
1002 )
1003 (assert_invalid
1004 (module (func $type-else-value-void-vs-nums (result i32 i32)
1005 (if (result i32 i32) (i32.const 1) (then (i32.const 0) (i32.const 0)) (else (nop)))
1006 ))
1007 "type mismatch"
1008 )
1009 (assert_invalid
1010 (module (func $type-both-value-void-vs-nums (result i32 i32)
1011 (if (result i32 i32) (i32.const 1) (then (nop)) (else (nop)))
1012 ))
1013 "type mismatch"
1014 )
1015
1016 (assert_invalid
1017 (module (func $type-then-value-num-vs-num (result i32)
1018 (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i32.const 1)))
1019 ))
1020 "type mismatch"
1021 )
1022 (assert_invalid
1023 (module (func $type-else-value-num-vs-num (result i32)
1024 (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i64.const 1)))
1025 ))
1026 "type mismatch"
1027 )
1028 (assert_invalid
1029 (module (func $type-both-value-num-vs-num (result i32)
1030 (if (result i32) (i32.const 1) (then (i64.const 1)) (else (i64.const 1)))
1031 ))
1032 "type mismatch"
1033 )
1034
1035 (assert_invalid
1036 (module (func $type-then-value-num-vs-nums (result i32 i32)
1037 (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
1038 ))
1039 "type mismatch"
1040 )
1041 (assert_invalid
1042 (module (func $type-else-value-num-vs-nums (result i32 i32)
1043 (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
1044 ))
1045 "type mismatch"
1046 )
1047 (assert_invalid
1048 (module (func $type-both-value-num-vs-nums (result i32 i32)
1049 (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
1050 ))
1051 "type mismatch"
1052 )
1053
1054 (assert_invalid
1055 (module (func $type-then-value-partial-vs-nums (result i32 i32)
1056 (i32.const 0)
1057 (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
1058 ))
1059 "type mismatch"
1060 )
1061 (assert_invalid
1062 (module (func $type-else-value-partial-vs-nums (result i32 i32)
1063 (i32.const 0)
1064 (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
1065 ))
1066 "type mismatch"
1067 )
1068 (assert_invalid
1069 (module (func $type-both-value-partial-vs-nums (result i32 i32)
1070 (i32.const 0)
1071 (if (result i32 i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
1072 ))
1073 "type mismatch"
1074 )
1075
1076 (assert_invalid
1077 (module (func $type-then-value-nums-vs-num (result i32)
1078 (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1)))
1079 ))
1080 "type mismatch"
1081 )
1082 (assert_invalid
1083 (module (func $type-else-value-nums-vs-num (result i32)
1084 (if (result i32) (i32.const 1) (then (i32.const 1)) (else (i32.const 1) (i32.const 1)))
1085 ))
1086 "type mismatch"
1087 )
1088 (assert_invalid
1089 (module (func $type-both-value-nums-vs-num (result i32)
1090 (if (result i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (i32.const 1) (i32.const 1)))
1091 ))
1092 "type mismatch"
1093 )
1094
1095 (assert_invalid
1096 (module (func $type-both-different-value-num-vs-num (result i32)
1097 (if (result i32) (i32.const 1) (then (i64.const 1)) (else (f64.const 1)))
1098 ))
1099 "type mismatch"
1100 )
1101 (assert_invalid
1102 (module (func $type-both-different-value-nums-vs-nums (result i32 i32)
1103 (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1) (i32.const 1)) (else (i32.const 1)))
1104 ))
1105 "type mismatch"
1106 )
1107
1108 (assert_invalid
1109 (module (func $type-then-value-unreached-select (result i32)
1110 (if (result i64)
1111 (i32.const 0)
1112 (then (select (unreachable) (unreachable) (unreachable)))
1113 (else (i64.const 0))
1114 )
1115 ))
1116 "type mismatch"
1117 )
1118 (assert_invalid
1119 (module (func $type-else-value-unreached-select (result i32)
1120 (if (result i64)
1121 (i32.const 1)
1122 (then (i64.const 0))
1123 (else (select (unreachable) (unreachable) (unreachable)))
1124 )
1125 ))
1126 "type mismatch"
1127 )
1128 (assert_invalid
1129 (module (func $type-else-value-unreached-select (result i32)
1130 (if (result i64)
1131 (i32.const 1)
1132 (then (select (unreachable) (unreachable) (unreachable)))
1133 (else (select (unreachable) (unreachable) (unreachable)))
1134 )
1135 ))
1136 "type mismatch"
1137 )
1138
1139 (assert_invalid
1140 (module (func $type-then-break-last-void-vs-num (result i32)
1141 (if (result i32) (i32.const 1) (then (br 0)) (else (i32.const 1)))
1142 ))
1143 "type mismatch"
1144 )
1145 (assert_invalid
1146 (module (func $type-else-break-last-void-vs-num (result i32)
1147 (if (result i32) (i32.const 1) (then (i32.const 1)) (else (br 0)))
1148 ))
1149 "type mismatch"
1150 )
1151 (assert_invalid
1152 (module (func $type-then-break-last-void-vs-nums (result i32 i32)
1153 (if (result i32 i32) (i32.const 1) (then (br 0)) (else (i32.const 1) (i32.const 1)))
1154 ))
1155 "type mismatch"
1156 )
1157 (assert_invalid
1158 (module (func $type-else-break-last-void-vs-nums (result i32 i32)
1159 (if (result i32 i32) (i32.const 1) (then (i32.const 1) (i32.const 1)) (else (br 0)))
1160 ))
1161 "type mismatch"
1162 )
1163
1164 (assert_invalid
1165 (module (func $type-then-break-empty-vs-num (result i32)
1166 (if (result i32) (i32.const 1)
1167 (then (br 0) (i32.const 1))
1168 (else (i32.const 1))
1169 )
1170 ))
1171 "type mismatch"
1172 )
1173 (assert_invalid
1174 (module (func $type-else-break-empty-vs-num (result i32)
1175 (if (result i32) (i32.const 1)
1176 (then (i32.const 1))
1177 (else (br 0) (i32.const 1))
1178 )
1179 ))
1180 "type mismatch"
1181 )
1182 (assert_invalid
1183 (module (func $type-then-break-empty-vs-nums (result i32 i32)
1184 (if (result i32 i32) (i32.const 1)
1185 (then (br 0) (i32.const 1) (i32.const 1))
1186 (else (i32.const 1) (i32.const 1))
1187 )
1188 ))
1189 "type mismatch"
1190 )
1191 (assert_invalid
1192 (module (func $type-else-break-empty-vs-nums (result i32 i32)
1193 (if (result i32 i32) (i32.const 1)
1194 (then (i32.const 1) (i32.const 1))
1195 (else (br 0) (i32.const 1) (i32.const 1))
1196 )
1197 ))
1198 "type mismatch"
1199 )
1200
1201 (assert_invalid
1202 (module (func $type-then-break-void-vs-num (result i32)
1203 (if (result i32) (i32.const 1)
1204 (then (br 0 (nop)) (i32.const 1))
1205 (else (i32.const 1))
1206 )
1207 ))
1208 "type mismatch"
1209 )
1210 (assert_invalid
1211 (module (func $type-else-break-void-vs-num (result i32)
1212 (if (result i32) (i32.const 1)
1213 (then (i32.const 1))
1214 (else (br 0 (nop)) (i32.const 1))
1215 )
1216 ))
1217 "type mismatch"
1218 )
1219 (assert_invalid
1220 (module (func $type-then-break-void-vs-nums (result i32 i32)
1221 (if (result i32 i32) (i32.const 1)
1222 (then (br 0 (nop)) (i32.const 1) (i32.const 1))
1223 (else (i32.const 1) (i32.const 1))
1224 )
1225 ))
1226 "type mismatch"
1227 )
1228 (assert_invalid
1229 (module (func $type-else-break-void-vs-nums (result i32 i32)
1230 (if (result i32 i32) (i32.const 1)
1231 (then (i32.const 1) (i32.const 1))
1232 (else (br 0 (nop)) (i32.const 1) (i32.const 1))
1233 )
1234 ))
1235 "type mismatch"
1236 )
1237
1238 (assert_invalid
1239 (module (func $type-then-break-num-vs-num (result i32)
1240 (if (result i32) (i32.const 1)
1241 (then (br 0 (i64.const 1)) (i32.const 1))
1242 (else (i32.const 1))
1243 )
1244 ))
1245 "type mismatch"
1246 )
1247 (assert_invalid
1248 (module (func $type-else-break-num-vs-num (result i32)
1249 (if (result i32) (i32.const 1)
1250 (then (i32.const 1))
1251 (else (br 0 (i64.const 1)) (i32.const 1))
1252 )
1253 ))
1254 "type mismatch"
1255 )
1256 (assert_invalid
1257 (module (func $type-then-break-num-vs-nums (result i32 i32)
1258 (if (result i32 i32) (i32.const 1)
1259 (then (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
1260 (else (i32.const 1) (i32.const 1))
1261 )
1262 ))
1263 "type mismatch"
1264 )
1265 (assert_invalid
1266 (module (func $type-else-break-num-vs-nums (result i32 i32)
1267 (if (result i32 i32) (i32.const 1)
1268 (then (i32.const 1) (i32.const 1))
1269 (else (br 0 (i64.const 1)) (i32.const 1) (i32.const 1))
1270 )
1271 ))
1272 "type mismatch"
1273 )
1274 (assert_invalid
1275 (module (func $type-then-break-partial-vs-nums (result i32 i32)
1276 (i32.const 1)
1277 (if (result i32 i32) (i32.const 1)
1278 (then (br 0 (i64.const 1)) (i32.const 1))
1279 (else (i32.const 1))
1280 )
1281 ))
1282 "type mismatch"
1283 )
1284 (assert_invalid
1285 (module (func $type-else-break-partial-vs-nums (result i32 i32)
1286 (i32.const 1)
1287 (if (result i32 i32) (i32.const 1)
1288 (then (i32.const 1))
1289 (else (br 0 (i64.const 1)) (i32.const 1))
1290 )
1291 ))
1292 "type mismatch"
1293 )
1294
1295 (assert_invalid
1296 (module
1297 (func $type-condition-empty
1298 (if (then))
1299 )
1300 )
1301 "type mismatch"
1302 )
1303 (assert_invalid
1304 (module
1305 (func $type-condition-empty-in-block
1306 (i32.const 0)
1307 (block (if (then)))
1308 )
1309 )
1310 "type mismatch"
1311 )
1312 (assert_invalid
1313 (module
1314 (func $type-condition-empty-in-loop
1315 (i32.const 0)
1316 (loop (if (then)))
1317 )
1318 )
1319 "type mismatch"
1320 )
1321 (assert_invalid
1322 (module
1323 (func $type-condition-empty-in-then
1324 (i32.const 0) (i32.const 0)
1325 (if (then (if (then))))
1326 )
1327 )
1328 "type mismatch"
1329 )
1330 (assert_invalid
1331 (module
1332 (func $type-condition-empty-in-else
1333 (i32.const 0) (i32.const 0)
1334 (if (result i32) (then (i32.const 0)) (else (if (then)) (i32.const 0)))
1335 (drop)
1336 )
1337 )
1338 "type mismatch"
1339 )
1340 (assert_invalid
1341 (module
1342 (func $type-condition-empty-in-br
1343 (i32.const 0)
1344 (block (br 0 (if(then))) (drop))
1345 )
1346 )
1347 "type mismatch"
1348 )
1349 (assert_invalid
1350 (module
1351 (func $type-condition-empty-in-br_if
1352 (i32.const 0)
1353 (block (br_if 0 (if(then)) (i32.const 1)) (drop))
1354 )
1355 )
1356 "type mismatch"
1357 )
1358 (assert_invalid
1359 (module
1360 (func $type-condition-empty-in-br_table
1361 (i32.const 0)
1362 (block (br_table 0 (if(then))) (drop))
1363 )
1364 )
1365 "type mismatch"
1366 )
1367 (assert_invalid
1368 (module
1369 (func $type-condition-empty-in-return
1370 (return (if(then))) (drop)
1371 )
1372 )
1373 "type mismatch"
1374 )
1375 (assert_invalid
1376 (module
1377 (func $type-condition-empty-in-select
1378 (select (if(then)) (i32.const 1) (i32.const 2)) (drop)
1379 )
1380 )
1381 "type mismatch"
1382 )
1383 (assert_invalid
1384 (module
1385 (func $type-condition-empty-in-call
1386 (call 1 (if(then))) (drop)
1387 )
1388 (func (param i32) (result i32) (local.get 0))
1389 )
1390 "type mismatch"
1391 )
1392 (assert_invalid
1393 (module
1394 (func $f (param i32) (result i32) (local.get 0))
1395 (type $sig (func (param i32) (result i32)))
1396 (table funcref (elem $f))
1397 (func $type-condition-empty-in-call_indirect
1398 (block (result i32)
1399 (call_indirect (type $sig)
1400 (if(then)) (i32.const 0)
1401 )
1402 (drop)
1403 )
1404 )
1405 )
1406 "type mismatch"
1407 )
1408 (assert_invalid
1409 (module
1410 (func $type-condition-empty-in-local.set
1411 (local i32)
1412 (local.set 0 (if(then))) (local.get 0) (drop)
1413 )
1414 )
1415 "type mismatch"
1416 )
1417 (assert_invalid
1418 (module
1419 (func $type-condition-empty-in-local.tee
1420 (local i32)
1421 (local.tee 0 (if(then))) (drop)
1422 )
1423 )
1424 "type mismatch"
1425 )
1426 (assert_invalid
1427 (module
1428 (global $x (mut i32) (i32.const 0))
1429 (func $type-condition-empty-in-global.set
1430 (global.set $x (if(then))) (global.get $x) (drop)
1431 )
1432 )
1433 "type mismatch"
1434 )
1435 (assert_invalid
1436 (module
1437 (memory 0)
1438 (func $type-condition-empty-in-memory.grow
1439 (memory.grow (if(then))) (drop)
1440 )
1441 )
1442 "type mismatch"
1443 )
1444 (assert_invalid
1445 (module
1446 (memory 0)
1447 (func $type-condition-empty-in-load
1448 (i32.load (if(then))) (drop)
1449 )
1450 )
1451 "type mismatch"
1452 )
1453 (assert_invalid
1454 (module
1455 (memory 1)
1456 (func $type-condition-empty-in-store
1457 (i32.store (if(then)) (i32.const 1))
1458 )
1459 )
1460 "type mismatch"
1461 )
1462
1463 (assert_invalid
1464 (module (func $type-param-void-vs-num
1465 (if (param i32) (i32.const 1) (then (drop)))
1466 ))
1467 "type mismatch"
1468 )
1469 (assert_invalid
1470 (module (func $type-param-void-vs-nums
1471 (if (param i32 f64) (i32.const 1) (then (drop) (drop)))
1472 ))
1473 "type mismatch"
1474 )
1475 (assert_invalid
1476 (module (func $type-param-num-vs-num
1477 (f32.const 0) (if (param i32) (i32.const 1) (then (drop)))
1478 ))
1479 "type mismatch"
1480 )
1481 (assert_invalid
1482 (module (func $type-param-num-vs-nums
1483 (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop)))
1484 ))
1485 "type mismatch"
1486 )
1487 (assert_invalid
1488 (module (func $type-param-nested-void-vs-num
1489 (block (if (param i32) (i32.const 1) (then (drop))))
1490 ))
1491 "type mismatch"
1492 )
1493 (assert_invalid
1494 (module (func $type-param-void-vs-nums
1495 (block (if (param i32 f64) (i32.const 1) (then (drop) (drop))))
1496 ))
1497 "type mismatch"
1498 )
1499 (assert_invalid
1500 (module (func $type-param-num-vs-num
1501 (block (f32.const 0) (if (param i32) (i32.const 1) (then (drop))))
1502 ))
1503 "type mismatch"
1504 )
1505 (assert_invalid
1506 (module (func $type-param-num-vs-nums
1507 (block (f32.const 0) (if (param f32 i32) (i32.const 1) (then (drop) (drop))))
1508 ))
1509 "type mismatch"
1510 )
1511
1512 (assert_malformed
1513 (module quote "(func (param i32) (result i32) if (param $x i32) end)")
1514 "unexpected token"
1515 )
1516 (assert_malformed
1517 (module quote "(func (param i32) (result i32) (if (param $x i32) (then)))")
1518 "unexpected token"
1519 )
1520
1521 (assert_malformed
1522 (module quote "(func i32.const 0 if end $l)")
1523 "mismatching label"
1524 )
1525 (assert_malformed
1526 (module quote "(func i32.const 0 if $a end $l)")
1527 "mismatching label"
1528 )
1529 (assert_malformed
1530 (module quote "(func i32.const 0 if else $l end)")
1531 "mismatching label"
1532 )
1533 (assert_malformed
1534 (module quote "(func i32.const 0 if $a else $l end)")
1535 "mismatching label"
1536 )
1537 (assert_malformed
1538 (module quote "(func i32.const 0 if else end $l)")
1539 "mismatching label"
1540 )
1541 (assert_malformed
1542 (module quote "(func i32.const 0 if else $l end $l)")
1543 "mismatching label"
1544 )
1545 (assert_malformed
1546 (module quote "(func i32.const 0 if else $l1 end $l2)")
1547 "mismatching label"
1548 )
1549 (assert_malformed
1550 (module quote "(func i32.const 0 if $a else end $l)")
1551 "mismatching label"
1552 )
1553 (assert_malformed
1554 (module quote "(func i32.const 0 if $a else $a end $l)")
1555 "mismatching label"
1556 )
1557 (assert_malformed
1558 (module quote "(func i32.const 0 if $a else $l end $l)")
1559 "mismatching label"
1560 )
1561 (assert_malformed
1562 (module quote "(func (if i32.const 0 (then) (else)))")
1563 "unexpected token"
1564 )