diff options
Diffstat (limited to 'llvm/lib/CodeGen/SjLjEHPrepare.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/SjLjEHPrepare.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/SjLjEHPrepare.cpp b/llvm/lib/CodeGen/SjLjEHPrepare.cpp index 054f7d721596..c33afdc71e78 100644 --- a/llvm/lib/CodeGen/SjLjEHPrepare.cpp +++ b/llvm/lib/CodeGen/SjLjEHPrepare.cpp @@ -267,11 +267,11 @@ void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) { Type *Ty = AI.getType(); - // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction. + // Use 'select i8 true, %arg, poison' to simulate a 'no-op' instruction. Value *TrueValue = ConstantInt::getTrue(F.getContext()); - Value *UndefValue = UndefValue::get(Ty); + Value *PoisonValue = PoisonValue::get(Ty); Instruction *SI = SelectInst::Create( - TrueValue, &AI, UndefValue, AI.getName() + ".tmp", AfterAllocaInsPt); + TrueValue, &AI, PoisonValue, AI.getName() + ".tmp", AfterAllocaInsPt); AI.replaceAllUsesWith(SI); // Reset the operand, because it was clobbered by the RAUW above. @@ -368,7 +368,7 @@ void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F, DemotePHIToStack(PN); // Move the landingpad instruction back to the top of the landing pad block. - LPI->moveBefore(&UnwindBlock->front()); + LPI->moveBefore(UnwindBlock->begin()); } } @@ -435,6 +435,10 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) { // where to look for it. Builder.CreateCall(FuncCtxFn, FuncCtx); + // Register the function context and make sure it's known to not throw. + CallInst *Register = Builder.CreateCall(RegisterFn, FuncCtx, ""); + Register->setDoesNotThrow(); + // At this point, we are all set up, update the invoke instructions to mark // their call_site values. for (unsigned I = 0, E = Invokes.size(); I != E; ++I) { @@ -457,15 +461,10 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) { if (&BB == &F.front()) continue; for (Instruction &I : BB) - if (I.mayThrow()) + if (!isa<InvokeInst>(I) && I.mayThrow()) insertCallSiteStore(&I, -1); } - // Register the function context and make sure it's known to not throw - CallInst *Register = CallInst::Create( - RegisterFn, FuncCtx, "", EntryBB->getTerminator()->getIterator()); - Register->setDoesNotThrow(); - // Following any allocas not in the entry block, update the saved SP in the // jmpbuf to the new value. for (BasicBlock &BB : F) { @@ -479,7 +478,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) { continue; } Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp"); - StackAddr->insertAfter(&I); + StackAddr->insertAfter(I.getIterator()); new StoreInst(StackAddr, StackPtr, true, std::next(StackAddr->getIterator())); } @@ -501,24 +500,26 @@ bool SjLjEHPrepareImpl::runOnFunction(Function &F) { Module &M = *F.getParent(); RegisterFn = M.getOrInsertFunction( "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()), - PointerType::getUnqual(FunctionContextTy)); + PointerType::getUnqual(FunctionContextTy->getContext())); UnregisterFn = M.getOrInsertFunction( "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()), - PointerType::getUnqual(FunctionContextTy)); + PointerType::getUnqual(FunctionContextTy->getContext())); PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext()); - FrameAddrFn = - Intrinsic::getDeclaration(&M, Intrinsic::frameaddress, {AllocaPtrTy}); - StackAddrFn = - Intrinsic::getDeclaration(&M, Intrinsic::stacksave, {AllocaPtrTy}); - StackRestoreFn = - Intrinsic::getDeclaration(&M, Intrinsic::stackrestore, {AllocaPtrTy}); + FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress, + {AllocaPtrTy}); + StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave, + {AllocaPtrTy}); + StackRestoreFn = Intrinsic::getOrInsertDeclaration( + &M, Intrinsic::stackrestore, {AllocaPtrTy}); BuiltinSetupDispatchFn = - Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch); - LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda); - CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite); - FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext); + Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch); + LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda); + CallSiteFn = + Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite); + FuncCtxFn = + Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext); bool Res = setupEntryBlockAndCallSites(F); return Res; |
