1; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test that function pointer casts that require conversions of arguments or
4; return types are converted to unreachable.
5
6target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7target triple = "wasm32-unknown-unknown"
8
9declare i32 @has_i64_arg(i64)
10declare i32 @has_ptr_arg(i8*)
11
12define void @test_invalid_rtn() {
13entry:
14  call i32 bitcast (i32 (i64)* @has_i64_arg to i32 (i32)*)(i32 0)
15  ret void
16}
17; CHECK-LABEL: test_invalid_rtn:
18; CHECK-NEXT: i32.const   $push[[L0:[0-9]+]]=, 0{{$}}
19; CHECK-NEXT: i32.call $push1=, .Lhas_i64_arg_bitcast_invalid@FUNCTION, $pop[[L0]]{{$}}
20; CHECK-NEXT: drop $pop1
21; CHECK-NEXT: end_function
22
23define void @test_invalid_arg() {
24entry:
25  call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i8)*)(i8 2)
26  call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i32)*)(i32 2)
27  call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i64)*)(i64 3)
28  ret void
29}
30
31; CHECK-LABEL: test_invalid_arg:
32; CHECK-NEXT: 	i32.const	$push[[L0:[0-9]+]]=, 2{{$}}
33; CHECK-NEXT: 	i32.call	$push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid.1@FUNCTION, $pop[[L0]]{{$}}
34; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
35; CHECK-NEXT: 	i32.const	$push[[L0:[0-9]+]]=, 2{{$}}
36; CHECK-NEXT: 	i32.call	$push[[L1:[0-9]+]]=, has_ptr_arg@FUNCTION, $pop[[L0]]{{$}}
37; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
38; CHECK-NEXT: 	i64.const	$push[[L0:[0-9]+]]=, 3{{$}}
39; CHECK-NEXT: 	i32.call	$push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid@FUNCTION, $pop[[L0]]{{$}}
40; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
41; CHECK-NEXT: 	end_function
42
43; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid:
44; CHECK-NEXT:  .param  	i32
45; CHECK-NEXT:  .result 	i32
46; CHECK-NEXT:  unreachable
47; CHECK-NEXT:  end_function
48
49; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid:
50; CHECK-NEXT: 	.param  	i64
51; CHECK-NEXT: 	.result 	i32
52; CHECK-NEXT: 	unreachable
53; CHECK-NEXT: 	end_function
54
55; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid.1:
56; CHECK-NEXT: 	.param  	i32
57; CHECK-NEXT: 	.result 	i32
58; CHECK-NEXT: 	unreachable
59; CHECK-NEXT: 	end_function
60