[InstCombine] Signed saturation patterns
[llvm-core.git] / test / CodeGen / WebAssembly / unsupported-function-bitcasts.ll
blob5db926912f356225d9b4d8a0de4b6244d38fdf52
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 datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7 target triple = "wasm32-unknown-unknown"
9 declare i32 @has_i64_arg(i64)
10 declare i32 @has_ptr_arg(i8*)
12 ; CHECK-LABEL: test_invalid_rtn:
13 ; CHECK:      i32.const   $push[[L0:[0-9]+]]=, 0{{$}}
14 ; CHECK-NEXT: i32.call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid.2, $pop[[L0]]{{$}}
15 ; CHECK-NEXT: drop $pop[[L1]]{{$}}
16 ; CHECK-NEXT: i64.const   $push[[L0:[0-9]+]]=, 0{{$}}
17 ; CHECK-NEXT: i64.call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid, $pop[[L0]]{{$}}
18 ; CHECK-NEXT: drop $pop[[L1]]{{$}}
19 ; CHECK-NEXT: end_function
20 define void @test_invalid_rtn() {
21 entry:
22   call i32 bitcast (i32 (i64)* @has_i64_arg to i32 (i32)*)(i32 0)
23   call [1 x i64] bitcast (i32 (i64)* @has_i64_arg to [1 x i64] (i64)*)(i64 0)
24   ret void
27 ; CHECK-LABEL: test_struct_rtn:
28 ; CHECK:        call            has_i64_arg, $pop6, $pop0
29 define void @test_struct_rtn() {
30   call {i32, i32} bitcast (i32 (i64)* @has_i64_arg to {i32, i32} (i64)*)(i64 0)
31   ret void
34 ; CHECK-LABEL: test_invalid_arg:
35 ; CHECK:        i32.const       $push[[L0:[0-9]+]]=, 2{{$}}
36 ; CHECK-NEXT:   i32.call        $push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid.4, $pop[[L0]]{{$}}
37 ; CHECK-NEXT:   drop    $pop[[L1]]{{$}}
38 ; CHECK-NEXT:   i32.const       $push[[L0:[0-9]+]]=, 2{{$}}
39 ; CHECK-NEXT:   i32.call        $push[[L1:[0-9]+]]=, has_ptr_arg, $pop[[L0]]{{$}}
40 ; CHECK-NEXT:   drop    $pop[[L1]]{{$}}
41 ; CHECK-NEXT:   i64.const       $push[[L0:[0-9]+]]=, 3{{$}}
42 ; CHECK-NEXT:   i32.call        $push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid, $pop[[L0]]{{$}}
43 ; CHECK-NEXT:   drop    $pop[[L1]]{{$}}
44 ; CHECK-NEXT:   end_function
45 define void @test_invalid_arg() {
46 entry:
47   call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i8)*)(i8 2)
48   call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i32)*)(i32 2)
49   call i32 bitcast (i32 (i8*)* @has_ptr_arg to i32 (i64)*)(i64 3)
50   ret void
53 ; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid:
54 ; CHECK-NEXT:  .functype .Lhas_i64_arg_bitcast_invalid (i64) -> (i64)
55 ; CHECK-NEXT:  unreachable
56 ; CHECK-NEXT:  end_function
58 ; CHECK-LABEL: .Lhas_i64_arg_bitcast_invalid.2:
59 ; CHECK-NEXT:  .functype .Lhas_i64_arg_bitcast_invalid.2 (i32) -> (i32)
60 ; CHECK-NEXT:  unreachable
61 ; CHECK-NEXT:  end_function
63 ; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid:
64 ; CHECK-NEXT:   .functype .Lhas_ptr_arg_bitcast_invalid (i64) -> (i32)
65 ; CHECK-NEXT:   unreachable
66 ; CHECK-NEXT:   end_function
68 ; CHECK-LABEL: .Lhas_ptr_arg_bitcast_invalid.4:
69 ; CHECK-NEXT:   .functype .Lhas_ptr_arg_bitcast_invalid.4 (i32) -> (i32)
70 ; CHECK-NEXT:   unreachable
71 ; CHECK-NEXT:   end_function