xref: /llvm-project/llvm/test/MC/WebAssembly/type-checker-errors.s (revision 991adff4628deeb3b4cb7d9df366e9f1e8b2860c)
1# RUN: not llvm-mc -triple=wasm32 -mattr=+exception-handling,+reference-types,+tail-call %s 2>&1 | FileCheck %s
2
3# These tests are intended to act as a litmus test for the WebAssembly ASM
4# type-checker - both in terms of errors it can catch and in terms of the
5# location information used in the error messages.
6
7local_get_no_local_type:
8  .functype local_get_no_local_type () -> ()
9# CHECK: :[[@LINE+1]]:13: error: no local type specified for index 0
10  local.get 0
11  end_function
12
13local_set_no_local_type:
14  .functype local_set_no_local_type () -> ()
15# CHECK: :[[@LINE+1]]:13: error: no local type specified for index 0
16  local.set 0
17  end_function
18
19local_set_empty_stack_while_popping:
20  .functype local_set_empty_stack_while_popping () -> ()
21  .local i32
22# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
23  local.set 0
24  end_function
25
26local_set_type_mismatch:
27  .functype local_set_type_mismatch () -> ()
28  .local i32
29  f32.const 1.0
30# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
31  local.set 0
32  end_function
33
34local_tee_no_local_type:
35  .functype local_tee_no_local_type () -> ()
36# CHECK: :[[@LINE+1]]:13: error: no local type specified for index 0
37  local.tee 0
38  end_function
39
40local_tee_empty_stack_while_popping:
41  .functype local_tee_empty_stack_while_popping () -> ()
42  .local f32
43# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got []
44  local.tee 0
45  end_function
46
47local_tee_type_mismatch:
48  .functype local_tee_type_mismatch () -> ()
49  .local f32
50  i32.const 1
51# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
52  local.tee 0
53  drop
54  end_function
55
56global_get_missing_globaltype:
57  .functype global_get_missing_globaltype () -> ()
58# CHECK: :[[@LINE+1]]:14: error: symbol foo: missing .globaltype
59  global.get foo
60  end_function
61
62global_get_expected_expression_operand:
63  .functype global_get_expected_expression_operand () -> ()
64# CHECK: :[[@LINE+1]]:14: error: expected expression operand
65  global.get 1
66  end_function
67
68global_set_missing_globaltype:
69  .functype global_set_missing_globaltype () -> ()
70# CHECK: :[[@LINE+1]]:14: error: symbol foo: missing .globaltype
71  global.set foo
72  end_function
73
74global_set_expected_expression_operand:
75  .functype global_set_expected_expression_operand () -> ()
76# CHECK: :[[@LINE+1]]:14: error: expected expression operand
77  global.set 1
78  end_function
79
80global_set_empty_stack_while_popping:
81  .functype global_set_empty_stack_while_popping () -> ()
82  .globaltype valid_global, i64
83# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i64] but got []
84  global.set valid_global
85  end_function
86
87global_set_type_mismatch:
88  .functype global_set_type_mismatch () -> ()
89  .globaltype valid_global, i64
90  i32.const 1
91# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i64] but got [i32]
92  global.set valid_global
93  end_function
94
95table_get_expected_expression_operand:
96  .functype table_get_expected_expression_operand () -> ()
97  i32.const 0
98# CHECK: :[[@LINE+1]]:13: error: expected expression operand
99  table.get 1
100  end_function
101
102table_get_missing_tabletype:
103  .functype table_get_missing_tabletype () -> ()
104  i32.const 0
105# CHECK: :[[@LINE+1]]:13: error: symbol foo: missing .tabletype
106  table.get foo
107  end_function
108
109.tabletype valid_table, externref
110
111table_get_empty_stack_while_popping:
112  .functype table_get_empty_stack_while_popping () -> ()
113# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
114  table.get valid_table
115  drop
116  end_function
117
118table_get_type_mismatch:
119  .functype table_get_type_mismatch () -> ()
120  f32.const 1.0
121# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
122  table.get valid_table
123  drop
124  end_function
125
126table_set_expected_expression_operand:
127  .functype table_set_expected_expression_operand () -> ()
128  i32.const 0
129# CHECK: :[[@LINE+1]]:13: error: expected expression operand
130  table.set 1
131  end_function
132
133table_set_missing_tabletype:
134  .functype table_set_missing_tabletype () -> ()
135  i32.const 0
136# CHECK: :[[@LINE+1]]:13: error: symbol foo: missing .tabletype
137  table.set foo
138  end_function
139
140table_set_empty_stack_while_popping_1:
141  .functype table_set_empty_stack_while_popping_1 () -> ()
142# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref] but got []
143  table.set valid_table
144  end_function
145
146table_set_empty_stack_while_popping_2:
147  .functype table_set_empty_stack_while_popping_2 (externref) -> ()
148  local.get 0
149# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref] but got [externref]
150  table.set valid_table
151  end_function
152
153table_set_type_mismatch_1:
154  .functype table_set_type_mismatch_1 () -> ()
155  i32.const 0
156  ref.null_func
157# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref] but got [i32, funcref]
158  table.set valid_table
159  end_function
160
161table_set_type_mismatch_2:
162  .functype table_set_type_mismatch_2 () -> ()
163  f32.const 1.0
164  ref.null_extern
165# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref] but got [f32, externref]
166  table.set valid_table
167  end_function
168
169table_fill_expected_expression_operand:
170  .functype table_fill_expected_expression_operand () -> ()
171  i32.const 0
172  ref.null_extern
173  i32.const 4
174# CHECK: :[[@LINE+1]]:14: error: expected expression operand
175  table.fill 1
176  end_function
177
178table_fill_missing_tabletype:
179  .functype table_fill_missing_tabletype () -> ()
180  i32.const 0
181  ref.null_extern
182  i32.const 4
183# CHECK: :[[@LINE+1]]:14: error: symbol foo: missing .tabletype
184  table.fill foo
185  end_function
186
187table_fill_empty_stack_while_popping_1:
188  .functype table_fill_empty_stack_while_popping_1 () -> ()
189# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got []
190  table.fill valid_table
191  end_function
192
193table_fill_empty_stack_while_popping_2:
194  .functype table_fill_empty_stack_while_popping_2 (i32) -> ()
195  local.get 0
196# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [i32]
197  table.fill valid_table
198  end_function
199
200table_fill_empty_stack_while_popping_3:
201  .functype table_fill_empty_stack_while_popping_3 (i32, externref) -> ()
202  local.get 1
203  local.get 0
204# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [externref, i32]
205  table.fill valid_table
206  end_function
207
208table_fill_type_mismatch_1:
209  .functype table_fill_type_mismatch_1 () -> ()
210  i32.const 0
211  ref.null_extern
212  ref.null_func
213# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [i32, externref, funcref]
214  table.fill valid_table
215  end_function
216
217table_fill_type_mismatch_2:
218  .functype table_fill_type_mismatch_2 () -> ()
219  i32.const 0
220  ref.null_func
221  i32.const 1
222# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [i32, funcref, i32]
223  table.fill valid_table
224  end_function
225
226table_fill_type_mismatch_3:
227  .functype table_fill_type_mismatch_3 () -> ()
228  f32.const 2.0
229  ref.null_extern
230  i32.const 1
231# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [f32, externref, i32]
232  table.fill valid_table
233  end_function
234
235table_fill_type_mismatch_4:
236  .functype table_fill_type_mismatch_4 () -> ()
237  i32.const 1
238  ref.null_exn
239  i32.const 1
240# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [i32, exnref, i32]
241  table.fill valid_table
242  end_function
243
244table_grow_non_exist_table:
245  .functype table_grow_non_exist_table (externref, i32) -> (i32)
246  local.get 0
247  local.get 1
248# CHECK: [[@LINE+1]]:14: error: symbol invalid_table: missing .tabletype
249  table.grow invalid_table
250  end_function
251
252table_grow_type_mismatch_1:
253  .functype table_grow_type_mismatch_1 (externref, i32) -> (i32)
254  local.get 1
255# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [externref, i32] but got [i32]
256  table.grow valid_table
257  end_function
258
259table_grow_type_mismatch_2:
260  .functype table_grow_type_mismatch_2 (externref, i32) -> (i32)
261  local.get 0
262  local.get 0
263# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [externref, i32] but got [externref, externref]
264  table.grow valid_table
265  end_function
266
267table_grow_wrong_result:
268  .functype table_grow_wrong_result (externref, i32) -> (f32)
269  local.get 0
270  local.get 1
271  table.grow valid_table
272# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
273  end_function
274
275drop_empty_stack_while_popping:
276  .functype drop_empty_stack_while_popping () -> ()
277# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
278  drop
279  end_function
280
281end_block_insufficient_values_on_stack_1:
282  .functype end_block_insufficient_values_on_stack_1 () -> ()
283  block i32
284# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
285  end_block
286  drop
287  end_function
288
289end_block_insufficient_values_on_stack_2:
290  .functype end_block_insufficient_values_on_stack_2 () -> ()
291  block () -> (i32)
292# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
293  end_block
294  drop
295  end_function
296
297end_block_type_mismatch:
298  .functype end_block_type_mismatch () -> ()
299  block i32
300    f32.const 1.0
301# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
302  end_block
303  drop
304  end_function
305
306end_loop_insufficient_values_on_stack:
307  .functype end_loop_insufficient_values_on_stack () -> ()
308  loop i32
309# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
310  end_loop
311  drop
312  end_function
313
314end_loop_type_mismatch:
315  .functype end_loop_type_mismatch () -> ()
316  loop f32
317    i32.const 1
318# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
319  end_loop
320  drop
321  end_function
322
323end_if_insufficient_values_on_stack_1:
324  .functype end_if_insufficient_values_on_stack_1 () -> ()
325  i32.const 1
326  if i32
327# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
328  end_if
329  end_function
330
331end_if_type_mismatch_1:
332  .functype end_if_type_mismatch_1 () -> ()
333  i32.const 1
334  if f32
335    i32.const 1
336# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
337  end_if
338  drop
339  end_function
340
341end_if_insufficient_values_on_stack_2:
342  .functype end_if_insufficient_values_on_stack_2 () -> ()
343  i32.const 1
344  if i32
345    i32.const 2
346  else
347# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
348  end_if
349  drop
350  end_function
351
352end_if_type_mismatch_2:
353  .functype end_if_type_mismatch_2 () -> ()
354  i32.const 1
355  if i32
356    i32.const 2
357  else
358    f32.const 3.0
359# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
360  end_if
361  drop
362  end_function
363
364else_insufficient_values_on_stack:
365  .functype else_insufficient_values_on_stack () -> ()
366  i32.const 1
367  if i32
368# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
369  else
370    i32.const 0
371  end_if
372  drop
373  end_function
374
375else_type_mismatch:
376  .functype else_type_mismatch () -> ()
377  i32.const 1
378  if i32
379    f32.const 0.0
380# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
381  else
382    i32.const 0
383  end_if
384  drop
385  end_function
386
387.tagtype tag_i32 i32
388.tagtype tag_f32 f32
389
390end_try_insufficient_values_on_stack:
391  .functype end_try_insufficient_values_on_stack () -> ()
392  try i32
393    i32.const 0
394  catch_all
395# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
396  end_try
397  drop
398  end_function
399
400end_try_type_mismatch:
401  .functype end_try_type_mismatch () -> ()
402  try i32
403    i32.const 0
404  catch tag_f32
405# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
406  end_try
407  drop
408  end_function
409
410catch_insufficient_values_on_stack:
411  .functype catch_insufficient_values_on_stack () -> ()
412  try i32
413# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
414  catch tag_i32
415  end_try
416  drop
417  end_function
418
419catch_type_mismatch:
420  .functype catch_type_mismatch () -> ()
421  try i32
422    f32.const 1.0
423# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
424  catch tag_i32
425  end_try
426  drop
427  end_function
428
429catch_all_insufficient_values_on_stack:
430  .functype catch_all_insufficient_values_on_stack () -> ()
431  try i32
432# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
433  catch_all
434    i32.const 0
435  end_try
436  drop
437  end_function
438
439catch_all_type_mismatch:
440  .functype catch_all_type_mismatch () -> ()
441  try i32
442    f32.const 1.0
443# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
444  catch_all
445    i32.const 0
446  end_try
447  drop
448  end_function
449
450delegate_insufficient_values_on_stack:
451  .functype delegate_insufficient_values_on_stack () -> ()
452  try i32
453# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
454  delegate 0
455  drop
456  end_function
457
458delegate_type_mismatch:
459  .functype delegate_type_mismatch () -> ()
460  try i32
461    f32.const 1.0
462# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
463  delegate 0
464  drop
465  end_function
466
467end_function_empty_stack_while_popping:
468  .functype end_function_empty_stack_while_popping () -> (i32)
469# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
470  end_function
471
472end_function_type_mismatch:
473  .functype end_function_type_mismatch () -> (f32)
474  i32.const 1
475# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
476  end_function
477
478end_function_superfluous_end_function_values:
479  .functype end_function_superfluous_end_function_values () -> ()
480  i32.const 1
481  f32.const 2.0
482# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [i32, f32]
483  end_function
484
485return_empty_stack_while_popping:
486  .functype return_empty_stack_while_popping () -> (i32)
487# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
488  return
489  end_function
490
491return_type_mismatch:
492  .functype return_type_mismatch () -> (f32)
493  i32.const 1
494# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
495  return
496  end_function
497
498# Missing index for call_indirect.
499call_indirect_empty_stack_while_popping_1:
500  .functype call_indirect_empty_stack_while_popping_1 () -> ()
501# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
502  call_indirect () -> ()
503  end_function
504
505# Missing arguments for target of call_indirect.
506call_indirect_empty_stack_while_popping_2:
507  .functype call_indirect_empty_stack_while_popping_1 (f32) -> ()
508  i32.const 1
509# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got []
510  call_indirect (f32) -> ()
511  end_function
512
513call_indirect_type_mismatch_for_argument:
514  .functype call_indirect_type_mismatch_for_argument () -> ()
515  i32.const 1
516  i32.const 2
517# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
518  call_indirect (f32) -> ()
519  end_function
520
521call_indirect_superfluous_value_at_end:
522  .functype call_indirect_superfluous_value_at_end () -> ()
523  i32.const 1
524  call_indirect () -> (i64)
525# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [i64]
526  end_function
527
528# Missing index for return_call_indirect.
529return_call_indirect_empty_stack_while_popping_1:
530  .functype return_call_indirect_empty_stack_while_popping_1 () -> ()
531# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
532  return_call_indirect () -> ()
533  end_function
534
535# Missing arguments for target of return_call_indirect.
536return_call_indirect_empty_stack_while_popping_2:
537  .functype return_call_indirect_empty_stack_while_popping_2 () -> ()
538  i32.const 1
539# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got []
540  return_call_indirect (f32) -> ()
541  end_function
542
543call_expected_expression_operand:
544  .functype call_expected_expression_operand () -> ()
545# CHECK: :[[@LINE+1]]:8: error: expected expression operand
546  call 1
547  end_function
548
549.functype fn_i32_to_void (i32) -> ()
550
551call_empty_stack_while_popping:
552  .functype call_empty_stack_while_popping () -> ()
553# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
554  call fn_i32_to_void
555  end_function
556
557call_type_mismatch:
558  .functype call_type_mismatch () -> ()
559  f32.const 1.0
560# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
561  call fn_i32_to_void
562  end_function
563
564.functype fn_void_to_i32 () -> (i32)
565
566call_superfluous_value_at_end:
567  .functype call_superfluous_value_at_end () -> ()
568  call fn_void_to_i32
569# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [i32]
570  end_function
571
572call_missing_functype:
573  .functype call_missing_functype () -> ()
574# CHECK: :[[@LINE+1]]:8: error: symbol no_functype: missing .functype
575  call no_functype
576  end_function
577
578return_call_expected_expression_operand:
579  .functype return_call_expected_expression_operand () -> ()
580# CHECK: :[[@LINE+1]]:15: error: expected expression operand
581  return_call 1
582  end_function
583
584return_call_empty_stack_while_popping:
585  .functype return_call_empty_stack_while_popping () -> ()
586# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
587  return_call fn_i32_to_void
588  end_function
589
590return_call_type_mismatch:
591  .functype return_call_type_mismatch () -> ()
592  f32.const 1.0
593# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
594  return_call fn_i32_to_void
595  end_function
596
597return_call_missing_functype:
598  .functype return_call_missing_functype () -> ()
599# CHECK: :[[@LINE+1]]:15: error: symbol no_functype: missing .functype
600  return_call no_functype
601  end_function
602
603catch_expected_expression_operand:
604  .functype catch_expected_expression_operand () -> ()
605  try
606# CHECK: :[[@LINE+1]]:9: error: expected expression operand
607  catch 1
608  end_try
609  end_function
610
611catch_missing_tagtype:
612  .functype catch_missing_tagtype () -> ()
613  try
614# CHECK: :[[@LINE+1]]:9: error: symbol no_tagtype: missing .tagtype
615  catch no_tagtype
616  end_try
617  end_function
618
619catch_superfluous_value_at_end:
620  .functype catch_superfluous_value_at_end () -> ()
621  try
622  catch tag_i32
623# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [i32]
624  end_try
625  end_function
626
627ref_is_null_empty_stack_while_popping:
628  .functype ref_is_null_empty_stack_while_popping () -> ()
629# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [ref] but got []
630  ref.is_null
631  drop
632  end_function
633
634ref_is_null_type_mismatch:
635  .functype ref_is_null_type_mismatch () -> ()
636  i32.const 1
637# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [ref] but got [i32]
638  ref.is_null
639  drop
640  end_function
641
642ref_is_null_pushes_i32:
643  .functype ref_is_null_pushes_i32 () -> (i64)
644  ref.null_func
645  ref.is_null
646# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i64] but got [i32]
647  end_function
648
649# For the other instructions, the type checker checks vs the operands in the
650# instruction definition. Perform some simple checks for these rather than
651# exhaustively testing all instructions.
652
653other_insn_test_1:
654  .functype other_insn_test_1 () -> ()
655# CHECK: [[@LINE+1]]:3: error: type mismatch, expected [i32, i32] but got []
656  i32.add
657  drop
658  end_function
659
660other_insn_test_2:
661  .functype other_insn_test_2 () -> ()
662  i32.const 1
663  ref.null_func
664# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, i32] but got [i32, funcref]
665  i32.add
666  drop
667  end_function
668
669other_insn_test_3:
670  .functype other_insn_test_3 () -> ()
671  f32.const 1.0
672  f32.const 2.0
673  f32.add
674# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [f32]
675  end_function
676
677# Unreachable code within 'block' does not affect type checking after
678# 'end_block'
679check_after_unreachable_within_block:
680  .functype check_after_unreachable_within_block () -> ()
681  block
682    unreachable
683  end_block
684# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
685  drop
686  end_function
687
688# Unreachable code within 'loop' does not affect type checking after 'end_loop'
689check_after_unreachable_within_loop:
690  .functype check_after_unreachable_within_loop () -> ()
691  loop
692    unreachable
693  end_loop
694# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
695  drop
696  end_function
697
698# Unreachable code within 'if' does not affect type checking after 'end_if'
699check_after_unreachable_within_if_1:
700  .functype check_after_unreachable_within_if_1 () -> ()
701  i32.const 0
702  if
703    unreachable
704  else
705    unreachable
706  end_if
707# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
708  drop
709  end_function
710
711# Unreachable code within 'if' does not affect type checking after 'else'
712check_after_unreachable_within_if_2:
713  .functype check_after_unreachable_within_if_2 () -> ()
714  i32.const 0
715  if
716    unreachable
717  else
718# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [any] but got []
719    drop
720  end_if
721  end_function
722
723# Unreachable code within 'try' does not affect type checking after 'end_try'
724check_after_unreachable_within_try_1:
725  .functype check_after_unreachable_within_try_1 () -> ()
726  try
727    unreachable
728  catch_all
729    unreachable
730  end_try
731# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
732  drop
733  end_function
734
735# Unreachable code within 'try' does not affect type checking after 'catch'
736check_after_unreachable_within_try_2:
737  .functype check_after_unreachable_within_try_2 () -> ()
738  try
739    unreachable
740  catch tag_i32
741    drop
742# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [any] but got []
743    drop
744  end_try
745  end_function
746
747# Unreachable code within 'try' does not affect type checking after 'catch_all'
748check_after_unreachable_within_try_3:
749  .functype check_after_unreachable_within_try_3 () -> ()
750  try
751    unreachable
752  catch_all
753# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [any] but got []
754    drop
755  end_try
756  end_function
757
758# Unreachable code within 'try' does not affect type checking after 'delegate'
759check_after_unreachable_within_try_4:
760  .functype check_after_unreachable_within_try_4 () -> ()
761  try
762    unreachable
763  delegate 0
764# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
765  drop
766  end_function
767
768br_invalid_type_loop:
769  .functype br_invalid_type_loop () -> ()
770  i32.const 1
771  loop (i32) -> (f32)
772    drop
773    f32.const 1.0
774# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [i32] but got [f32]
775    br 0
776  end_loop
777  drop
778  end_function
779
780br_invalid_type_block:
781  .functype br_invalid_type_block () -> ()
782  i32.const 1
783  block (i32) -> (f32)
784# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [f32] but got [i32]
785    br 0
786    f32.const 1.0
787  end_block
788  drop
789  end_function
790
791br_invalid_type_if:
792  .functype br_invalid_type_if () -> ()
793  i32.const 1
794  if f32
795    f32.const 1.0
796  else
797    i32.const 1
798# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [f32] but got [i32]
799    br 0
800  end_if
801  drop
802  end_function
803
804br_invalid_type_try:
805  .functype br_invalid_type_try () -> ()
806  try f32
807    i32.const 1
808# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [f32] but got [i32]
809    br 0
810  catch tag_f32
811  end_try
812  drop
813  end_function
814
815br_invalid_type_catch:
816  .functype br_invalid_type_catch () -> ()
817  try f32
818    f32.const 1.0
819  catch tag_i32
820# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [f32] but got [i32]
821    br 0
822  end_try
823  drop
824  end_function
825
826br_invalid_type_catch_all:
827  .functype br_invalid_type_catch_all () -> ()
828  try f32
829    f32.const 1.0
830  catch_all
831    i32.const 1
832# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [f32] but got [i32]
833    br 0
834  end_try
835  drop
836  end_function
837
838br_invalid_depth_out_of_range:
839  .functype br_invalid_depth_out_of_range () -> ()
840  block
841    block
842      block
843# CHECK: :[[@LINE+1]]:9: error: br: invalid depth 4
844        br 4
845      end_block
846    end_block
847  end_block
848  end_function
849
850br_incorrect_signature:
851  .functype br_incorrect_signature () -> ()
852  block f32
853    block i32
854      i32.const 1
855# CHECK: :[[@LINE+1]]:7: error: type mismatch, expected [f32] but got [i32]
856      br 1
857    end_block
858    drop
859    f32.const 1.0
860  end_block
861  drop
862  end_function
863
864br_incorrect_func_signature:
865  .functype br_incorrect_func_signature () -> (i32)
866  block f32
867    f32.const 1.0
868# CHECK: :[[@LINE+1]]:5: error: type mismatch, expected [i32] but got [f32]
869    br 1
870  end_block
871  drop
872  i32.const 1
873  end_function
874
875multiple_errors_in_function:
876  .functype multiple_errors_in_function () -> ()
877# CHECK: :[[@LINE+2]]:3: error: type mismatch, expected [i32] but got []
878# CHECK: :[[@LINE+1]]:13: error: expected expression operand
879  table.get 1
880
881# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, externref, i32] but got [any]
882  table.fill valid_table
883
884  f32.const 0.0
885  ref.null_extern
886# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, i32] but got [f32, externref]
887  i32.add
888  drop
889  end_function
890
891.functype take_and_return_multi(i32, i64, f32, f64) -> (i32, i64, f32, f64)
892
893call_with_multi_param_and_return:
894  .functype call_with_multi_param_and_return () -> (i32)
895  ref.null_extern
896  f32.const 0.0
897# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32, i64, f32, f64] but got [externref, f32]
898  call take_and_return_multi
899# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [i32, i64, f32, f64]
900  end_function
901
902.functype callee (f32, i32) -> ()
903
904any_value_on_stack:
905  .functype any_value_on_stack () -> ()
906  # This local does not exist so it should error out, but it should put an 'any'
907  # value on the stack so 'call callee' should not error out again
908# CHECK: :[[@LINE+1]]:13: error: no local type specified for index 0
909  local.get 0
910  i32.const 0
911# CHECK-NOT: :[[@LINE+1]]:3: error: type mismatch
912  call callee
913
914  # But this time 'call callee' should error out
915  i32.const 0
916# CHECK: :[[@LINE+1]]:13: error: no local type specified for index 0
917  local.get 0
918# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32, i32] but got [i32, any]
919  call callee
920
921# CHECK: :[[@LINE+2]]:13: error: no local type specified for index 0
922# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [any] but got []
923  local.set 0
924  drop
925
926  end_function
927
928block_param_and_return:
929  .functype block_param_and_return () -> ()
930# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got []
931  block (i32) -> (f32)
932# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [i32]
933  end_block
934# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [i32] but got [f32]
935  i32.popcnt
936  drop
937
938  block f32
939    f32.const 0.0
940    br 0
941    i32.const 0
942# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [f32] but got [..., i32]
943  end_block
944
945# CHECK: :[[@LINE+1]]:3: error: type mismatch, expected [] but got [f32]
946  end_function
947
948  .tagtype  __cpp_exception i32
949
950eh_test:
951  .functype eh_test () -> ()
952  block i32
953    block i32
954      block i32
955        block
956# CHECK: :[[@LINE+4]]:11: error: try_table: catch index 0: type mismatch, catch tag type is [i32], but destination's type is []
957# CHECK: :[[@LINE+3]]:11: error: try_table: catch index 1: type mismatch, catch tag type is [i32, exnref], but destination's type is [i32]
958# CHECK: :[[@LINE+2]]:11: error: try_table: catch index 2: type mismatch, catch tag type is [], but destination's type is [i32]
959# CHECK: :[[@LINE+1]]:11: error: try_table: catch index 3: type mismatch, catch tag type is [exnref], but destination's type is [i32]
960          try_table i32 (catch __cpp_exception 0) (catch_ref __cpp_exception 1) (catch_all 2) (catch_all_ref 3)
961# CHECK: :[[@LINE+1]]:11: error: type mismatch, expected [i32] but got []
962          end_try_table
963          drop
964        end_block
965      end_block
966    end_block
967  end_block
968  drop
969
970  loop
971  i32.const 0
972    loop (i32) -> ()
973      loop (i32) -> ()
974        loop
975# CHECK: :[[@LINE+4]]:11: error: try_table: catch index 0: type mismatch, catch tag type is [i32], but destination's type is []
976# CHECK: :[[@LINE+3]]:11: error: try_table: catch index 1: type mismatch, catch tag type is [i32, exnref], but destination's type is [i32]
977# CHECK: :[[@LINE+2]]:11: error: try_table: catch index 2: type mismatch, catch tag type is [], but destination's type is [i32]
978# CHECK: :[[@LINE+1]]:11: error: try_table: catch index 3: type mismatch, catch tag type is [exnref], but destination's type is []
979          try_table (catch __cpp_exception 0) (catch_ref __cpp_exception 1) (catch_all 2) (catch_all_ref 3)
980          end_try_table
981        end_loop
982        drop
983      end_loop
984    end_loop
985  end_loop
986  end_function
987