summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kaylor <andrew.kaylor@intel.com>2015-04-23 18:37:39 +0000
committerAndrew Kaylor <andrew.kaylor@intel.com>2015-04-23 18:37:39 +0000
commit71ed98da5c8566e70e58f86d7969f0f1f795b13b (patch)
treee502720afd6b8930a57b0d3a4b55c5872ddf223c
parent70e56ae6b3772061bf7a6590b51a9a916e954626 (diff)
[WinEH] Handle stubs for outlined functions that have only unreached terminators.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235618 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/WinEHPrepare.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp
index 57671f0937..03f53cda83 100644
--- a/lib/CodeGen/WinEHPrepare.cpp
+++ b/lib/CodeGen/WinEHPrepare.cpp
@@ -1037,6 +1037,7 @@ static BasicBlock *createStubLandingPad(Function *Handler,
void WinEHPrepare::addStubInvokeToHandlerIfNeeded(Function *Handler,
Value *PersonalityFn) {
ReturnInst *Ret = nullptr;
+ UnreachableInst *Unreached = nullptr;
for (BasicBlock &BB : *Handler) {
TerminatorInst *Terminator = BB.getTerminator();
// If we find an invoke, there is nothing to be done.
@@ -1044,18 +1045,24 @@ void WinEHPrepare::addStubInvokeToHandlerIfNeeded(Function *Handler,
if (II)
return;
// If we've already recorded a return instruction, keep looking for invokes.
- if (Ret)
- continue;
- // If we haven't recorded a return instruction yet, try this terminator.
- Ret = dyn_cast<ReturnInst>(Terminator);
+ if (!Ret)
+ Ret = dyn_cast<ReturnInst>(Terminator);
+ // If we haven't recorded an unreachable instruction, try this terminator.
+ if (!Unreached)
+ Unreached = dyn_cast<UnreachableInst>(Terminator);
}
// If we got this far, the handler contains no invokes. We should have seen
- // at least one return. We'll insert an invoke of llvm.donothing ahead of
- // that return.
- assert(Ret);
- BasicBlock *OldRetBB = Ret->getParent();
- BasicBlock *NewRetBB = SplitBlock(OldRetBB, Ret);
+ // at least one return or unreachable instruction. We'll insert an invoke of
+ // llvm.donothing ahead of that instruction.
+ assert(Ret || Unreached);
+ TerminatorInst *Term;
+ if (Ret)
+ Term = Ret;
+ else
+ Term = Unreached;
+ BasicBlock *OldRetBB = Term->getParent();
+ BasicBlock *NewRetBB = SplitBlock(OldRetBB, Term);
// SplitBlock adds an unconditional branch instruction at the end of the
// parent block. We want to replace that with an invoke call, so we can
// erase it now.