llvm.org GIT mirror llvm / 87f92ec
[WebAssembly] Reapply r319186: "Support bitcasted function addresses with varargs." This puts the functionality under control of a command-line option which is off by default to avoid breaking existing setups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320197 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 2 years ago
4 changed file(s) with 51 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
198198
199199 // Bitcasted vararg functions occur in Emscripten's implementation of
200200 // EM_ASM, so suppress wrappers for them for now.
201 if (Ty->isVarArg() || F->isVarArg())
201 if (TemporaryWorkarounds && (Ty->isVarArg() || F->isVarArg()))
202202 continue;
203203
204204 auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr));
None ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -fast-isel -fast-isel-abort=1 | FileCheck %s
0 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-temporary-workarounds=false | FileCheck %s
1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -fast-isel -fast-isel-abort=1 -wasm-temporary-workarounds=false | FileCheck %s
22
33 ; Test that basic call operations assemble as expected.
44
152152 ; CHECK-LABEL: call_constexpr:
153153 ; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}}
154154 ; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 3{{$}}
155 ; CHECK-NEXT: call vararg_func@FUNCTION, $pop[[L0]], $pop[[L1]]{{$}}
155 ; CHECK-NEXT: call .Lbitcast@FUNCTION, $pop[[L0]], $pop[[L1]]{{$}}
156156 ; CHECK-NEXT: call other_void_nullary@FUNCTION{{$}}
157157 ; CHECK-NEXT: call void_nullary@FUNCTION{{$}}
158158 ; CHECK-NEXT: return{{$}}
0 ; RUN: llc < %s -asm-verbose=false -wasm-temporary-workarounds=false | FileCheck %s
1
2 ; Test that function pointer casts casting away varargs are replaced with
3 ; wrappers.
4
5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown-wasm"
7
8 define void @callWithArgs() {
9 entry:
10 call void bitcast (void (...)* @underspecified to void (i32, i32)*)(i32 0, i32 1)
11 call void(...) bitcast (void (i32, i32)* @specified to void (...)*)(i32 0, i32 1)
12 ret void
13 }
14
15 declare void @underspecified(...)
16 declare void @specified(i32, i32)
17
18 ; CHECK: callWithArgs:
19 ; CHECK: i32.const $push1=, 0
20 ; CHECK-NEXT: i32.const $push0=, 1
21 ; CHECK-NEXT: call .Lbitcast@FUNCTION, $pop1, $pop0
22 ; CHECK: call .Lbitcast.1@FUNCTION, $pop{{[0-9]+$}}
23
24 ; CHECK: .Lbitcast:
25 ; CHECK-NEXT: .param i32, i32{{$}}
26 ; CHECK: call underspecified@FUNCTION, $pop{{[0-9]+$}}
27
28 ; CHECK: .Lbitcast.1:
29 ; CHECK-NEXT: .param i32{{$}}
30 ; CHECK: call specified@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+$}}
None ; RUN: llc < %s -asm-verbose=false -disable-wasm-explicit-locals -enable-emscripten-cxx-exceptions | FileCheck %s
0 ; RUN: llc < %s -asm-verbose=false -disable-wasm-explicit-locals -enable-emscripten-cxx-exceptions -wasm-temporary-workarounds=false | FileCheck %s
11
22 ; Test that function pointer casts are replaced with wrappers.
33
1919 ; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
2020 ; CHECK-NEXT: call .Lbitcast.1@FUNCTION{{$}}
2121 ; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0
22 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L0]]{{$}}
22 ; CHECK-NEXT: call .Lbitcast.4@FUNCTION, $pop[[L0]]{{$}}
2323 ; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0
24 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L1]]{{$}}
24 ; CHECK-NEXT: call .Lbitcast.4@FUNCTION, $pop[[L1]]{{$}}
2525 ; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 0
26 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L2]]{{$}}
26 ; CHECK-NEXT: call .Lbitcast.4@FUNCTION, $pop[[L2]]{{$}}
2727 ; CHECK-NEXT: call foo0@FUNCTION
28 ; CHECK-NEXT: i32.call $drop=, .Lbitcast.3@FUNCTION{{$}}
28 ; CHECK-NEXT: i32.call $drop=, .Lbitcast.5@FUNCTION{{$}}
2929 ; CHECK-NEXT: call foo2@FUNCTION{{$}}
3030 ; CHECK-NEXT: call foo1@FUNCTION{{$}}
3131 ; CHECK-NEXT: call foo3@FUNCTION{{$}}
5353 ; CHECK-LABEL: test_varargs:
5454 ; CHECK: set_global
5555 ; CHECK: i32.const $push[[L3:[0-9]+]]=, 0{{$}}
56 ; CHECK-NEXT: call vararg@FUNCTION, $pop[[L3]]{{$}}
56 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L3]]{{$}}
5757 ; CHECK-NEXT: i32.const $push[[L4:[0-9]+]]=, 0{{$}}
5858 ; CHECK-NEXT: i32.store 0($[[L5:[0-9]+]]), $pop[[L4]]{{$}}
59 ; CHECK-NEXT: call plain@FUNCTION, $[[L5]]{{$}}
59 ; CHECK-NEXT: call .Lbitcast.3@FUNCTION, $[[L5]]{{$}}
6060 define void @test_varargs() {
6161 call void bitcast (void (...)* @vararg to void (i32)*)(i32 0)
6262 call void (...) bitcast (void (i32)* @plain to void (...)*)(i32 0)
146146 ; CHECK-NEXT: end_function
147147
148148 ; CHECK-LABEL: .Lbitcast.2:
149 ; CHECK: call vararg@FUNCTION, $1{{$}}
150 ; CHECK: end_function
151
152 ; CHECK-LABEL: .Lbitcast.3:
153 ; CHECK: call plain@FUNCTION, $1{{$}}
154 ; CHECK: end_function
155
156 ; CHECK-LABEL: .Lbitcast.4:
149157 ; CHECK-NEXT: .param i32
150158 ; CHECK-NEXT: call foo0@FUNCTION{{$}}
151159 ; CHECK-NEXT: end_function
152160
153 ; CHECK-LABEL: .Lbitcast.3:
161 ; CHECK-LABEL: .Lbitcast.5:
154162 ; CHECK-NEXT: .result i32
155163 ; CHECK-NEXT: call foo1@FUNCTION{{$}}
156164 ; CHECK-NEXT: copy_local $push0=, $0