diff options
author | Derek Schuff <dschuff@google.com> | 2017-12-08 00:39:54 +0000 |
---|---|---|
committer | Derek Schuff <dschuff@google.com> | 2017-12-08 00:39:54 +0000 |
commit | 9e1baeda745ca4edd517d30644a71784313ceb5a (patch) | |
tree | 3cc2c0039e3273686c2db995fcc1ef84ef63525a /llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | |
parent | 323ba39f101ca87be4a93e6967ab89ef93071053 (diff) | |
download | bcm5719-llvm-9e1baeda745ca4edd517d30644a71784313ceb5a.tar.gz bcm5719-llvm-9e1baeda745ca4edd517d30644a71784313ceb5a.zip |
Revert "[WebAssemby] Support main functions with alternate signatures."
This reverts commit 959e37e669b0c3cfad4cb9f1f7c9261ce9f5e9ae.
That commit doesn't handle the case where main is declared rather than defined,
in particular the even-more special case where main is a prototypeless
declaration (which is of course the one actually used by musl currently).
llvm-svn: 320121
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | 46 |
1 files changed, 1 insertions, 45 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp index 4888bf3a747..f1d2c00d163 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -142,41 +142,11 @@ static Function *CreateWrapper(Function *F, FunctionType *Ty) { } bool FixFunctionBitcasts::runOnModule(Module &M) { - Function *Main = nullptr; - CallInst *CallMain = nullptr; SmallVector<std::pair<Use *, Function *>, 0> Uses; SmallPtrSet<Constant *, 2> ConstantBCs; // Collect all the places that need wrappers. - for (Function &F : M) { - FindUses(&F, F, Uses, ConstantBCs); - - // If we have a "main" function, and its type isn't - // "int main(int argc, char *argv[])", create an artificial call with it - // bitcasted to that type so that we generate a wrapper for it, so that - // the C runtime can call it. - if (F.getName() == "main") { - Main = &F; - LLVMContext &C = M.getContext(); - Type *MainArgTys[] = { - PointerType::get(Type::getInt8PtrTy(C), 0), - Type::getInt32Ty(C) - }; - FunctionType *MainTy = FunctionType::get(Type::getInt32Ty(C), MainArgTys, - /*isVarArg=*/false); - if (F.getFunctionType() != MainTy) { - Value *Args[] = { - UndefValue::get(MainArgTys[0]), - UndefValue::get(MainArgTys[1]) - }; - Value *Casted = ConstantExpr::getBitCast(Main, - PointerType::get(MainTy, 0)); - CallMain = CallInst::Create(Casted, Args, "call_main"); - Use *UseMain = &CallMain->getOperandUse(2); - Uses.push_back(std::make_pair(UseMain, &F)); - } - } - } + for (Function &F : M) FindUses(&F, F, Uses, ConstantBCs); DenseMap<std::pair<Function *, FunctionType *>, Function *> Wrappers; @@ -211,19 +181,5 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { U->set(Wrapper); } - // If we created a wrapper for main, rename the wrapper so that it's the - // one that gets called from startup. - if (CallMain) { - Main->setName("__original_main"); - Function *MainWrapper = - cast<Function>(CallMain->getCalledValue()->stripPointerCasts()); - MainWrapper->setName("main"); - MainWrapper->setLinkage(Main->getLinkage()); - MainWrapper->setVisibility(Main->getVisibility()); - Main->setLinkage(Function::PrivateLinkage); - Main->setVisibility(Function::DefaultVisibility); - delete CallMain; - } - return true; } |