• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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
12; CHECK-LABEL: test_invalid_rtn:
13; CHECK:      i32.const   $push[[L0:[0-9]+]]=, 0{{$}}
14; CHECK-NEXT: 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: call $push[[L1:[0-9]+]]=, .Lhas_i64_arg_bitcast_invalid, $pop[[L0]]{{$}}
18; CHECK-NEXT: drop $pop[[L1]]{{$}}
19; CHECK-NEXT: end_function
20define void @test_invalid_rtn() {
21entry:
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
25}
26
27; CHECK-LABEL: test_struct_rtn:
28; CHECK: 	call    	has_i64_arg, $pop6, $pop0
29define void @test_struct_rtn() {
30  call {i32, i32} bitcast (i32 (i64)* @has_i64_arg to {i32, i32} (i64)*)(i64 0)
31  ret void
32}
33
34; CHECK-LABEL: test_invalid_arg:
35; CHECK:      	i32.const	$push[[L0:[0-9]+]]=, 2{{$}}
36; CHECK-NEXT: 	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: 	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: 	call	$push[[L1:[0-9]+]]=, .Lhas_ptr_arg_bitcast_invalid, $pop[[L0]]{{$}}
43; CHECK-NEXT: 	drop	$pop[[L1]]{{$}}
44; CHECK-NEXT: 	end_function
45define void @test_invalid_arg() {
46entry:
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
51}
52
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
57
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
62
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
67
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
72