Don't try to add stack protector logic to a dead basic block. It messes up
authorBill Wendling <isanbard@gmail.com>
Tue, 29 Mar 2011 05:15:48 +0000 (05:15 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 29 Mar 2011 05:15:48 +0000 (05:15 +0000)
dominator information.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128452 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/StackProtector.cpp

index 1a588e25d6e3fa2bc9dff99c89edc348e25d2875..d90cb39e23fe5afb9cccbf4dc655486a949bbf8f 100644 (file)
@@ -150,9 +150,11 @@ 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;
@@ -178,7 +180,6 @@ bool StackProtector::InsertStackProtectors() {
         StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy); 
       }
 
-      BasicBlock &Entry = F->getEntryBlock();
       Instruction *InsPt = &Entry.front();
 
       AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);