blob: 9cafdd5bc2c8ba369b07850dbd6717fc97b0d372 [file] [log] [blame]
Dan Gohman1b637452017-01-07 00:34:54 +00001; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test that function pointer casts are replaced with wrappers.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8; CHECK-LABEL: test:
9; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
Derek Schuff7acb42a2017-01-10 21:59:53 +000010; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
Dan Gohman1b637452017-01-07 00:34:54 +000011; CHECK-NEXT: call .Lbitcast.1@FUNCTION{{$}}
Dan Gohman0e2ceb82017-01-07 01:50:01 +000012; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0
Dan Gohman1b637452017-01-07 00:34:54 +000013; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L0]]{{$}}
Derek Schuff7acb42a2017-01-10 21:59:53 +000014; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0
15; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L1]]{{$}}
16; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 0
17; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L2]]{{$}}
18; CHECK-NEXT: call foo0@FUNCTION
Dan Gohman1b637452017-01-07 00:34:54 +000019; CHECK-NEXT: i32.call $drop=, .Lbitcast.3@FUNCTION{{$}}
20; CHECK-NEXT: call foo2@FUNCTION{{$}}
Derek Schuff7acb42a2017-01-10 21:59:53 +000021; CHECK-NEXT: call foo1@FUNCTION{{$}}
Dan Gohman1b637452017-01-07 00:34:54 +000022; CHECK-NEXT: call foo3@FUNCTION{{$}}
23; CHECK-NEXT: .endfunc
24
Dan Gohmana99b7172017-01-20 20:50:29 +000025; CHECK-LABEL: test_varargs:
26; CHECK-NEXT: .local i32
27; CHECK: store
28; CHECK: i32.const $push[[L3:[0-9]+]]=, 0{{$}}
29; CHECK-NEXT: call vararg@FUNCTION, $pop[[L3]]{{$}}
30; CHECK-NEXT: i32.const $push[[L4:[0-9]+]]=, 0{{$}}
31; CHECK-NEXT: i32.store 0($[[L5:[0-9]+]]), $pop[[L4]]{{$}}
32; CHECK-NEXT: call plain@FUNCTION, $[[L5]]{{$}}
33
Dan Gohman1b637452017-01-07 00:34:54 +000034; CHECK-LABEL: .Lbitcast:
35; CHECK-NEXT: .local i32
36; CHECK-NEXT: call has_i32_arg@FUNCTION, $0{{$}}
37; CHECK-NEXT: .endfunc
38
39; CHECK-LABEL: .Lbitcast.1:
40; CHECK-NEXT: call $drop=, has_i32_ret@FUNCTION{{$}}
41; CHECK-NEXT: .endfunc
42
43; CHECK-LABEL: .Lbitcast.2:
44; CHECK-NEXT: .param i32
45; CHECK-NEXT: call foo0@FUNCTION{{$}}
46; CHECK-NEXT: .endfunc
47
48; CHECK-LABEL: .Lbitcast.3:
49; CHECK-NEXT: .result i32
50; CHECK-NEXT: .local i32
51; CHECK-NEXT: call foo1@FUNCTION{{$}}
52; CHECK-NEXT: copy_local $push0=, $0
53; CHECK-NEXT: .endfunc
54
55declare void @has_i32_arg(i32)
56declare i32 @has_i32_ret()
Dan Gohmana99b7172017-01-20 20:50:29 +000057declare void @vararg(...)
58declare void @plain(i32)
Dan Gohman1b637452017-01-07 00:34:54 +000059
60declare void @foo0()
61declare void @foo1()
62declare void @foo2()
63declare void @foo3()
64
65define void @test() {
66entry:
67 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
Derek Schuff7acb42a2017-01-10 21:59:53 +000068 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
Dan Gohman1b637452017-01-07 00:34:54 +000069 call void bitcast (i32 ()* @has_i32_ret to void ()*)()
70 call void bitcast (void ()* @foo0 to void (i32)*)(i32 0)
Derek Schuff7acb42a2017-01-10 21:59:53 +000071 %p = bitcast void ()* @foo0 to void (i32)*
72 call void %p(i32 0)
73 %q = bitcast void ()* @foo0 to void (i32)*
74 call void %q(i32 0)
75 %r = bitcast void (i32)* %q to void ()*
76 call void %r()
Dan Gohman1b637452017-01-07 00:34:54 +000077 %t = call i32 bitcast (void ()* @foo1 to i32 ()*)()
78 call void bitcast (void ()* @foo2 to void ()*)()
Derek Schuff7acb42a2017-01-10 21:59:53 +000079 call void @foo1()
Dan Gohman1b637452017-01-07 00:34:54 +000080 call void @foo3()
Derek Schuff7acb42a2017-01-10 21:59:53 +000081
Dan Gohman1b637452017-01-07 00:34:54 +000082 ret void
83}
Dan Gohmana99b7172017-01-20 20:50:29 +000084
85define void @test_varargs() {
86 call void bitcast (void (...)* @vararg to void (i32)*)(i32 0)
87 call void (...) bitcast (void (i32)* @plain to void (...)*)(i32 0)
88 ret void
89}