[llvm] r354544 - [WebAssembly] Default to something reasonable in WebAssemblyAddMissingPrototypes
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 20 19:27:01 PST 2019
Author: sbc
Date: Wed Feb 20 19:27:00 2019
New Revision: 354544
URL: http://llvm.org/viewvc/llvm-project?rev=354544&view=rev
Log:
[WebAssembly] Default to something reasonable in WebAssemblyAddMissingPrototypes
Previously if we couldn't derive a prototype for a "no-prototype"
function from C we would leave it as is:
void foo(...)
With this change we instead give is an empty signature and remove
the "no-prototype" attribute.
This fixes the current wasm waterfall test failure.
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58488
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp?rev=354544&r1=354543&r2=354544&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp Wed Feb 20 19:27:00 2019
@@ -86,7 +86,6 @@ bool WebAssemblyAddMissingPrototypes::ru
// Create a function prototype based on the first call site (first bitcast)
// that we find.
FunctionType *NewType = nullptr;
- Function *NewF = nullptr;
for (Use &U : F.uses()) {
LLVM_DEBUG(dbgs() << "prototype-less use: " << F.getName() << "\n");
LLVM_DEBUG(dbgs() << *U.getUser() << "\n");
@@ -97,10 +96,6 @@ bool WebAssemblyAddMissingPrototypes::ru
// Create a new function with the correct type
NewType = DestType;
LLVM_DEBUG(dbgs() << "found function type: " << *NewType << "\n");
- NewF = Function::Create(NewType, F.getLinkage(), F.getName() + ".fixed_sig");
- NewF->setAttributes(F.getAttributes());
- NewF->removeFnAttr("no-prototype");
- Replacements.emplace_back(&F, NewF);
} else if (NewType != DestType) {
errs() << "warning: prototype-less function used with "
"conflicting signatures: "
@@ -116,8 +111,19 @@ bool WebAssemblyAddMissingPrototypes::ru
LLVM_DEBUG(
dbgs() << "could not derive a function prototype from usage: " +
F.getName() + "\n");
- continue;
+ // We could not derive a type for this function. In this case strip
+ // the isVarArg and make it a simple zero-arg function. This has more
+ // chance of being correct. The current signature of (...) is illegal in
+ // C since it doesn't have any arguments before the "...", we this at
+ // least makes it possible for this symbol to be resolved by the linker.
+ NewType = FunctionType::get(F.getFunctionType()->getReturnType(), false);
}
+
+ Function *NewF =
+ Function::Create(NewType, F.getLinkage(), F.getName() + ".fixed_sig");
+ NewF->setAttributes(F.getAttributes());
+ NewF->removeFnAttr("no-prototype");
+ Replacements.emplace_back(&F, NewF);
}
for (auto &Pair : Replacements) {
@@ -126,7 +132,7 @@ bool WebAssemblyAddMissingPrototypes::ru
std::string Name = OldF->getName();
M.getFunctionList().push_back(NewF);
OldF->replaceAllUsesWith(
- ConstantExpr::getPointerBitCastOrAddrSpaceCast(NewF, OldF->getType()));
+ ConstantExpr::getPointerBitCastOrAddrSpaceCast(NewF, OldF->getType()));
OldF->eraseFromParent();
NewF->setName(Name);
}
Modified: llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll?rev=354544&r1=354543&r2=354544&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/add-prototypes.ll Wed Feb 20 19:27:00 2019
@@ -58,6 +58,9 @@ define void @as_paramater() {
declare void @func_param(i64 (...)*)
+; CHECK: declare void @func_not_called()
+declare void @func_not_called(...) #1
+
; CHECK: declare extern_weak i64 @foo(i32)
declare extern_weak i64 @foo(...) #1
More information about the llvm-commits
mailing list