blob: 3f20aef081159b6354f64970aa4b4207ce4fece0 [file] [log] [blame]
Dan Gohman7d7409e2017-02-28 23:37:04 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-explicit-locals | FileCheck %s
Dan Gohman1b637452017-01-07 00:34:54 +00002
3; Test that function pointer casts are replaced with wrappers.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman7d7409e2017-02-28 23:37:04 +00006target triple = "wasm32-unknown-unknown-wasm"
Dan Gohman1b637452017-01-07 00:34:54 +00007
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{{$}}
Dan Gohman7d7409e2017-02-28 23:37:04 +000023; CHECK-NEXT: end_function
Dan Gohman1b637452017-01-07 00:34:54 +000024
Dan Gohmana99b7172017-01-20 20:50:29 +000025; CHECK-LABEL: test_varargs:
Dan Gohman7d7409e2017-02-28 23:37:04 +000026; CHECK: set_global
Dan Gohmana99b7172017-01-20 20:50:29 +000027; CHECK: i32.const $push[[L3:[0-9]+]]=, 0{{$}}
28; CHECK-NEXT: call vararg@FUNCTION, $pop[[L3]]{{$}}
29; CHECK-NEXT: i32.const $push[[L4:[0-9]+]]=, 0{{$}}
30; CHECK-NEXT: i32.store 0($[[L5:[0-9]+]]), $pop[[L4]]{{$}}
31; CHECK-NEXT: call plain@FUNCTION, $[[L5]]{{$}}
32
Dan Gohman1b637452017-01-07 00:34:54 +000033; CHECK-LABEL: .Lbitcast:
Dan Gohman1b637452017-01-07 00:34:54 +000034; CHECK-NEXT: call has_i32_arg@FUNCTION, $0{{$}}
Dan Gohman7d7409e2017-02-28 23:37:04 +000035; CHECK-NEXT: end_function
Dan Gohman1b637452017-01-07 00:34:54 +000036
37; CHECK-LABEL: .Lbitcast.1:
38; CHECK-NEXT: call $drop=, has_i32_ret@FUNCTION{{$}}
Dan Gohman7d7409e2017-02-28 23:37:04 +000039; CHECK-NEXT: end_function
Dan Gohman1b637452017-01-07 00:34:54 +000040
41; CHECK-LABEL: .Lbitcast.2:
42; CHECK-NEXT: .param i32
43; CHECK-NEXT: call foo0@FUNCTION{{$}}
Dan Gohman7d7409e2017-02-28 23:37:04 +000044; CHECK-NEXT: end_function
Dan Gohman1b637452017-01-07 00:34:54 +000045
46; CHECK-LABEL: .Lbitcast.3:
47; CHECK-NEXT: .result i32
Dan Gohman1b637452017-01-07 00:34:54 +000048; CHECK-NEXT: call foo1@FUNCTION{{$}}
49; CHECK-NEXT: copy_local $push0=, $0
Dan Gohman7d7409e2017-02-28 23:37:04 +000050; CHECK-NEXT: end_function
Dan Gohman1b637452017-01-07 00:34:54 +000051
52declare void @has_i32_arg(i32)
53declare i32 @has_i32_ret()
Dan Gohmana99b7172017-01-20 20:50:29 +000054declare void @vararg(...)
55declare void @plain(i32)
Dan Gohman1b637452017-01-07 00:34:54 +000056
57declare void @foo0()
58declare void @foo1()
59declare void @foo2()
60declare void @foo3()
61
62define void @test() {
63entry:
64 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
Derek Schuff7acb42a2017-01-10 21:59:53 +000065 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
Dan Gohman1b637452017-01-07 00:34:54 +000066 call void bitcast (i32 ()* @has_i32_ret to void ()*)()
67 call void bitcast (void ()* @foo0 to void (i32)*)(i32 0)
Derek Schuff7acb42a2017-01-10 21:59:53 +000068 %p = bitcast void ()* @foo0 to void (i32)*
69 call void %p(i32 0)
70 %q = bitcast void ()* @foo0 to void (i32)*
71 call void %q(i32 0)
72 %r = bitcast void (i32)* %q to void ()*
73 call void %r()
Dan Gohman1b637452017-01-07 00:34:54 +000074 %t = call i32 bitcast (void ()* @foo1 to i32 ()*)()
75 call void bitcast (void ()* @foo2 to void ()*)()
Derek Schuff7acb42a2017-01-10 21:59:53 +000076 call void @foo1()
Dan Gohman1b637452017-01-07 00:34:54 +000077 call void @foo3()
Derek Schuff7acb42a2017-01-10 21:59:53 +000078
Dan Gohman1b637452017-01-07 00:34:54 +000079 ret void
80}
Dan Gohmana99b7172017-01-20 20:50:29 +000081
82define void @test_varargs() {
83 call void bitcast (void (...)* @vararg to void (i32)*)(i32 0)
84 call void (...) bitcast (void (i32)* @plain to void (...)*)(i32 0)
85 ret void
86}