Fix a bug that occurred when removing the last predecessor INTO an
authorChris Lattner <sabre@nondot.org>
Fri, 25 Apr 2003 23:14:19 +0000 (23:14 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 25 Apr 2003 23:14:19 +0000 (23:14 +0000)
infinite loop

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

lib/VMCore/BasicBlock.cpp

index 04f4e1cfc0d95863954562eb28ec2adae62c30a8..d04e5546162620c2c6cccdab2f82ee2c4b8b707b 100644 (file)
@@ -186,7 +186,11 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
 
       // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
       if (max_idx == 2) {
-       PN->replaceAllUsesWith(PN->getOperand(0));
+        if (PN->getOperand(0) != PN)
+          PN->replaceAllUsesWith(PN->getOperand(0));
+        else
+          // We are left with an infinite loop with no entries: kill the PHI.
+          PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
         getInstList().pop_front();    // Remove the PHI node
       }