1 ; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
3 ; Test that function pointer casts that require conversions of arguments or
4 ; return types are converted to unreachable.
6 target triple = "wasm32-unknown-unknown"
8 declare i32 @has_i64_arg(i64)
9 declare i32 @has_ptr_arg(i8*)
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
19 define void @test_invalid_rtn() {
21 call i32 bitcast (i32 (i64)* @has_i64_arg to i32 (i32)*)(i32 0)
22 call [1 x i64] bitcast (i32 (i64)* @has_i64_arg to [1 x i64] (i64)*)(i64 0)
26 ; CHECK-LABEL: test_struct_rtn:
27 ; CHECK: call has_i64_arg, $pop6, $pop0
28 define void @test_struct_rtn() {
29 call {i32, i32} bitcast (i32 (i64)* @has_i64_arg to {i32, i32} (i64)*)(i64 0)
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
44 define void @test_invalid_arg() {
46 call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i8)*)(i8 2)
47 call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i32)*)(i32 2)
48 call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i64)*)(i64 3)
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
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
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
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