summaryrefslogtreecommitdiff
path: root/lib/CodeGen/StackProtector.cpp
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-08-09 21:26:18 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-08-09 21:26:18 +0000
commit236e389be4bb7f65e78bd378143b67f401f05338 (patch)
tree09f093f716ef16d6a970f4466bae585d2080a003 /lib/CodeGen/StackProtector.cpp
parent4c71064129d1e5def34d74ee47c4f3beaa0a66df (diff)
downloadllvm-236e389be4bb7f65e78bd378143b67f401f05338.tar.gz
llvm-236e389be4bb7f65e78bd378143b67f401f05338.tar.bz2
llvm-236e389be4bb7f65e78bd378143b67f401f05338.tar.xz
[stackprotector] Simplify SP Pass so that we emit different fail basic blocks for each fail condition.
This patch decouples the stack protector pass so that we can support stack protector implementations that do not use the IR level generated stack protector fail basic block. No codesize increase is caused by this change since the MI level tail merge pass properly merges together the fail condition blocks (see the updated test). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188105 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackProtector.cpp')
-rw-r--r--lib/CodeGen/StackProtector.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp
index 4c5638092e..f8c98266dd 100644
--- a/lib/CodeGen/StackProtector.cpp
+++ b/lib/CodeGen/StackProtector.cpp
@@ -312,8 +312,7 @@ static void CreatePrologue(Function *F, Module *M, ReturnInst *RI,
/// - The epilogue checks the value stored in the prologue against the original
/// value. It calls __stack_chk_fail if they differ.
bool StackProtector::InsertStackProtectors() {
- BasicBlock *FailBB = 0; // The basic block to jump to if check fails.
- BasicBlock *FailBBDom = 0; // FailBB's dominator.
+ bool HasPrologue = false;
AllocaInst *AI = 0; // Place on stack that stores the stack guard.
Value *StackGuardVar = 0; // The stack guard variable.
@@ -322,10 +321,9 @@ bool StackProtector::InsertStackProtectors() {
ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
if (!RI) continue;
- if (!FailBB) {
+ if (!HasPrologue) {
+ HasPrologue = true;
CreatePrologue(F, M, RI, TLI, Trip, AI, StackGuardVar);
- // Create the basic block to jump to when the guard check fails.
- FailBB = CreateFailBB();
}
// For each block with a return instruction, convert this:
@@ -350,12 +348,16 @@ bool StackProtector::InsertStackProtectors() {
// call void @__stack_chk_fail()
// unreachable
+ // Create the fail basic block.
+ BasicBlock *FailBB = CreateFailBB();
+
// Split the basic block before the return instruction.
BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
+ // Update the dominator tree if we need to.
if (DT && DT->isReachableFromEntry(BB)) {
DT->addNewBlock(NewBB, BB);
- FailBBDom = FailBBDom ? DT->findNearestCommonDominator(FailBBDom, BB) :BB;
+ DT->addNewBlock(FailBB, BB);
}
// Remove default branch instruction to the new BB.
@@ -374,10 +376,8 @@ bool StackProtector::InsertStackProtectors() {
// Return if we didn't modify any basic blocks. I.e., there are no return
// statements in the function.
- if (!FailBB) return false;
-
- if (DT && FailBBDom)
- DT->addNewBlock(FailBB, FailBBDom);
+ if (!HasPrologue)
+ return false;
return true;
}