xref: /llvm-project/llvm/test/CodeGen/WebAssembly/unsupported-function-bitcasts.ll (revision 73856247eef35f5336e485dc009842a5b991c421)
1; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
2
3; Test that function pointer casts that require conversions of arguments or
4; return types are converted to unreachable.
5
6target triple = "wasm32-unknown-unknown"
7
8declare i32 @has_i64_arg(i64)
9declare i32 @has_ptr_arg(ptr)
10
11; CHECK-LABEL: test_invalid_rtn:
12; CHECK:      i32.const   $push[[L0:[0-9]+]]=, 0{{$}}
13; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid.2, $pop[[L0]]{{$}}
14; CHECK-NEXT: drop $pop[[L1]]{{$}}
15; CHECK-NEXT: i64.const   $push[[L0:[0-9]+]]=, 0{{$}}
16; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid, $pop[[L0]]{{$}}
17; CHECK-NEXT: drop $pop[[L1]]{{$}}
18; CHECK-NEXT: end_function
19define void @test_invalid_rtn() {
20entry:
21  call i32 @has_i64_arg(i32 0)
22  call [1 x i64] @has_i64_arg(i64 0)
23  ret void
24}
25
26; CHECK-LABEL: test_struct_rtn:
27; CHECK: 	call    	has_i64_arg, $pop6, $pop0
28define void @test_struct_rtn() {
29  call {i32, i32} @has_i64_arg(i64 0)
30  ret void
31}
32
33; CHECK-LABEL: test_invalid_arg:
34; CHECK:      	i32.const	$push[[L0:[0-9]+]]=, 2{{$}}
35; CHECK-NEXT: 	call	$push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid.4, $pop[[L0]]{{$}}
36; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
37; CHECK-NEXT: 	i32.const	$push[[L0:[0-9]+]]=, 2{{$}}
38; CHECK-NEXT: 	call	$push[[L1:[0-9]+]]=, has_ptr_arg, $pop[[L0]]{{$}}
39; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
40; CHECK-NEXT: 	i64.const	$push[[L0:[0-9]+]]=, 3{{$}}
41; CHECK-NEXT: 	call	$push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid, $pop[[L0]]{{$}}
42; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
43; CHECK-NEXT: 	end_function
44define void @test_invalid_arg() {
45entry:
46  call i32 @has_ptr_arg(i8 2)
47  call i32 @has_ptr_arg(i32 2)
48  call i32 @has_ptr_arg(i64 3)
49  ret void
50}
51
52; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid:
53; CHECK-NEXT:  .functype .Lhas_i64_arg_bitcast_invalid (i64) -> (i64)
54; CHECK-NEXT:  unreachable
55; CHECK-NEXT:  end_function
56
57; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid.2:
58; CHECK-NEXT:  .functype .Lhas_i64_arg_bitcast_invalid.2 (i32) -> (i32)
59; CHECK-NEXT:  unreachable
60; CHECK-NEXT:  end_function
61
62; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid:
63; CHECK-NEXT: 	.functype .Lhas_ptr_arg_bitcast_invalid (i64) -> (i32)
64; CHECK-NEXT: 	unreachable
65; CHECK-NEXT: 	end_function
66
67; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid.4:
68; CHECK-NEXT: 	.functype .Lhas_ptr_arg_bitcast_invalid.4 (i32) -> (i32)
69; CHECK-NEXT: 	unreachable
70; CHECK-NEXT: 	end_function
71