18a9cb242SWouter van Oortmerssen; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s 20e2ceb81SDan Gohman 341d7047dSSam Clegg; Test that function pointer casts that require conversions of arguments or 441d7047dSSam Clegg; return types are converted to unreachable. 50e2ceb81SDan Gohman 6a5908009SSam Cleggtarget triple = "wasm32-unknown-unknown" 70e2ceb81SDan Gohman 841d7047dSSam Cleggdeclare i32 @has_i64_arg(i64) 941d7047dSSam Cleggdeclare i32 @has_ptr_arg(i8*) 100e2ceb81SDan Gohman 1188599bf6SSam Clegg; CHECK-LABEL: test_invalid_rtn: 1249482f82SWouter van Oortmerssen; CHECK: i32.const $push[[L0:[0-9]+]]=, 0{{$}} 13*ca9ba764SThomas Lively; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid.2, $pop[[L0]]{{$}} 1488599bf6SSam Clegg; CHECK-NEXT: drop $pop[[L1]]{{$}} 1588599bf6SSam Clegg; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, 0{{$}} 16*ca9ba764SThomas Lively; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid, $pop[[L0]]{{$}} 1788599bf6SSam Clegg; CHECK-NEXT: drop $pop[[L1]]{{$}} 1888599bf6SSam Clegg; CHECK-NEXT: end_function 1941d7047dSSam Cleggdefine void @test_invalid_rtn() { 200e2ceb81SDan Gohmanentry: 2141d7047dSSam Clegg call i32 bitcast (i32 (i64)* @has_i64_arg to i32 (i32)*)(i32 0) 2288599bf6SSam Clegg call [1 x i64] bitcast (i32 (i64)* @has_i64_arg to [1 x i64] (i64)*)(i64 0) 230e2ceb81SDan Gohman ret void 240e2ceb81SDan Gohman} 2541d7047dSSam Clegg 2688599bf6SSam Clegg; CHECK-LABEL: test_struct_rtn: 27275d15ecSSam Clegg; CHECK: call has_i64_arg, $pop6, $pop0 2888599bf6SSam Cleggdefine void @test_struct_rtn() { 2988599bf6SSam Clegg call {i32, i32} bitcast (i32 (i64)* @has_i64_arg to {i32, i32} (i64)*)(i64 0) 3041d7047dSSam Clegg ret void 3141d7047dSSam Clegg} 3241d7047dSSam Clegg 3341d7047dSSam Clegg; CHECK-LABEL: test_invalid_arg: 3449482f82SWouter van Oortmerssen; CHECK: i32.const $push[[L0:[0-9]+]]=, 2{{$}} 35*ca9ba764SThomas Lively; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid.4, $pop[[L0]]{{$}} 3641d7047dSSam Clegg; CHECK-NEXT: drop $pop[[L1]]{{$}} 3741d7047dSSam Clegg; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}} 38*ca9ba764SThomas Lively; CHECK-NEXT: call $push[[L1:[0-9]+]]=, has_ptr_arg, $pop[[L0]]{{$}} 3941d7047dSSam Clegg; CHECK-NEXT: drop $pop[[L1]]{{$}} 4041d7047dSSam Clegg; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, 3{{$}} 41*ca9ba764SThomas Lively; CHECK-NEXT: call $push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid, $pop[[L0]]{{$}} 4241d7047dSSam Clegg; CHECK-NEXT: drop $pop[[L1]]{{$}} 4341d7047dSSam Clegg; CHECK-NEXT: end_function 4488599bf6SSam Cleggdefine void @test_invalid_arg() { 4588599bf6SSam Cleggentry: 4688599bf6SSam Clegg call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i8)*)(i8 2) 4788599bf6SSam Clegg call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i32)*)(i32 2) 4888599bf6SSam Clegg call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i64)*)(i64 3) 4988599bf6SSam Clegg ret void 5088599bf6SSam Clegg} 5141d7047dSSam Clegg 5241d7047dSSam Clegg; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid: 5349482f82SWouter van Oortmerssen; CHECK-NEXT: .functype .Lhas_i64_arg_bitcast_invalid (i64) -> (i64) 5488599bf6SSam Clegg; CHECK-NEXT: unreachable 5588599bf6SSam Clegg; CHECK-NEXT: end_function 5688599bf6SSam Clegg 5788599bf6SSam Clegg; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid.2: 5849482f82SWouter van Oortmerssen; CHECK-NEXT: .functype .Lhas_i64_arg_bitcast_invalid.2 (i32) -> (i32) 5941d7047dSSam Clegg; CHECK-NEXT: unreachable 6041d7047dSSam Clegg; CHECK-NEXT: end_function 6141d7047dSSam Clegg 6241d7047dSSam Clegg; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid: 6349482f82SWouter van Oortmerssen; CHECK-NEXT: .functype .Lhas_ptr_arg_bitcast_invalid (i64) -> (i32) 6441d7047dSSam Clegg; CHECK-NEXT: unreachable 6541d7047dSSam Clegg; CHECK-NEXT: end_function 6641d7047dSSam Clegg 6788599bf6SSam Clegg; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid.4: 6849482f82SWouter van Oortmerssen; CHECK-NEXT: .functype .Lhas_ptr_arg_bitcast_invalid.4 (i32) -> (i32) 6941d7047dSSam Clegg; CHECK-NEXT: unreachable 7041d7047dSSam Clegg; CHECK-NEXT: end_function 71