[llvm] r292645 - [WebAssembly] Don't create bitcast-wrappers for varargs.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 12:50:29 PST 2017
Author: djg
Date: Fri Jan 20 14:50:29 2017
New Revision: 292645
URL: http://llvm.org/viewvc/llvm-project?rev=292645&view=rev
Log:
[WebAssembly] Don't create bitcast-wrappers for varargs.
WebAssembly varargs functions use a significantly different ABI than
non-varargs functions, and the current code in
WebAssemblyFixFunctionBitcasts doesn't handle that difference. For now,
just avoid creating wrapper functions in the presence of varargs.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
llvm/trunk/test/CodeGen/WebAssembly/function-bitcasts.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp?rev=292645&r1=292644&r2=292645&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp Fri Jan 20 14:50:29 2017
@@ -148,6 +148,11 @@ bool FixFunctionBitcasts::runOnModule(Mo
if (!Ty)
continue;
+ // Wasm varargs are not ABI-compatible with non-varargs. Just ignore
+ // such casts for now.
+ if (Ty->isVarArg() || F->isVarArg())
+ continue;
+
auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr));
if (Pair.second)
Pair.first->second = CreateWrapper(F, Ty);
Modified: llvm/trunk/test/CodeGen/WebAssembly/function-bitcasts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/function-bitcasts.ll?rev=292645&r1=292644&r2=292645&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/function-bitcasts.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/function-bitcasts.ll Fri Jan 20 14:50:29 2017
@@ -22,6 +22,15 @@ target triple = "wasm32-unknown-unknown"
; CHECK-NEXT: call foo3 at FUNCTION{{$}}
; CHECK-NEXT: .endfunc
+; CHECK-LABEL: test_varargs:
+; CHECK-NEXT: .local i32
+; CHECK: store
+; CHECK: i32.const $push[[L3:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: call vararg at FUNCTION, $pop[[L3]]{{$}}
+; CHECK-NEXT: i32.const $push[[L4:[0-9]+]]=, 0{{$}}
+; CHECK-NEXT: i32.store 0($[[L5:[0-9]+]]), $pop[[L4]]{{$}}
+; CHECK-NEXT: call plain at FUNCTION, $[[L5]]{{$}}
+
; CHECK-LABEL: .Lbitcast:
; CHECK-NEXT: .local i32
; CHECK-NEXT: call has_i32_arg at FUNCTION, $0{{$}}
@@ -45,6 +54,8 @@ target triple = "wasm32-unknown-unknown"
declare void @has_i32_arg(i32)
declare i32 @has_i32_ret()
+declare void @vararg(...)
+declare void @plain(i32)
declare void @foo0()
declare void @foo1()
@@ -70,3 +81,9 @@ entry:
ret void
}
+
+define void @test_varargs() {
+ call void bitcast (void (...)* @vararg to void (i32)*)(i32 0)
+ call void (...) bitcast (void (i32)* @plain to void (...)*)(i32 0)
+ ret void
+}
More information about the llvm-commits
mailing list