summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/StackProtector.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2011-03-29 07:28:52 +0000
committerBill Wendling <isanbard@gmail.com>2011-03-29 07:28:52 +0000
commitfb63d55fe8e0b9a919a7ed1cc5b535304b5c97c9 (patch)
tree4080a013f0d096195b131f9d31026cab642c56ce /llvm/lib/CodeGen/StackProtector.cpp
parentff811cc47535141fb44946e44608ac612a992581 (diff)
downloadbcm5719-llvm-fb63d55fe8e0b9a919a7ed1cc5b535304b5c97c9.tar.gz
bcm5719-llvm-fb63d55fe8e0b9a919a7ed1cc5b535304b5c97c9.zip
Rework the logic (and removing the bad check for an unreachable block) so that
the FailBB dominator is correctly calculated. Believe it or not, there isn't a functionality change here. llvm-svn: 128455
Diffstat (limited to 'llvm/lib/CodeGen/StackProtector.cpp')
-rw-r--r--llvm/lib/CodeGen/StackProtector.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index d90cb39e23f..b3ee152d28b 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -150,12 +150,9 @@ bool StackProtector::InsertStackProtectors() {
BasicBlock *FailBBDom = 0; // FailBB's dominator.
AllocaInst *AI = 0; // Place on stack that stores the stack guard.
Value *StackGuardVar = 0; // The stack guard variable.
- BasicBlock &Entry = F->getEntryBlock();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ) {
BasicBlock *BB = I++;
- if (BB->getNumUses() == 0 && BB != &Entry) continue;
-
ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
if (!RI) continue;
@@ -180,6 +177,7 @@ bool StackProtector::InsertStackProtectors() {
StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy);
}
+ BasicBlock &Entry = F->getEntryBlock();
Instruction *InsPt = &Entry.front();
AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);
@@ -192,8 +190,6 @@ bool StackProtector::InsertStackProtectors() {
// Create the basic block to jump to when the guard check fails.
FailBB = CreateFailBB();
- if (DT)
- FailBBDom = DT->isReachableFromEntry(BB) ? BB : 0;
}
// For each block with a return instruction, convert this:
@@ -219,11 +215,12 @@ bool StackProtector::InsertStackProtectors() {
// unreachable
// Split the basic block before the return instruction.
+ bool BBIsReachable = (DT && DT->isReachableFromEntry(BB));
BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
- if (DT && DT->isReachableFromEntry(BB)) {
+
+ if (BBIsReachable) {
DT->addNewBlock(NewBB, BB);
- if (FailBBDom)
- FailBBDom = DT->findNearestCommonDominator(FailBBDom, BB);
+ FailBBDom = FailBBDom ? DT->findNearestCommonDominator(FailBBDom, BB) :BB;
}
// Remove default branch instruction to the new BB.
OpenPOWER on IntegriCloud