diff options
| author | Sam Clegg <sbc@chromium.org> | 2019-02-21 03:27:00 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2019-02-21 03:27:00 +0000 |
| commit | 1634516e3538b9df51fd479b28ef18355a5c4a66 (patch) | |
| tree | 936f650878caa582566f49e895a4fab51b8b4641 /llvm/lib/Target/WebAssembly | |
| parent | 42e229e13082a5dfb39aa43b40a8d7c75df92770 (diff) | |
| download | bcm5719-llvm-1634516e3538b9df51fd479b28ef18355a5c4a66.tar.gz bcm5719-llvm-1634516e3538b9df51fd479b28ef18355a5c4a66.zip | |
[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
llvm-svn: 354544
Diffstat (limited to 'llvm/lib/Target/WebAssembly')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp index 8604d9e1799..3e13369f33e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp @@ -86,7 +86,6 @@ bool WebAssemblyAddMissingPrototypes::runOnModule(Module &M) { // 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::runOnModule(Module &M) { // 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::runOnModule(Module &M) { 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::runOnModule(Module &M) { 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); } |

