Fix Transforms/SimplifyCFG/switch-simplify-crash.ll
authorChris Lattner <sabre@nondot.org>
Fri, 20 May 2005 22:19:54 +0000 (22:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 May 2005 22:19:54 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22158 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index 15ea761f2ce78d82a12b036c9db7bd2bb8934947..ad78506ad425d33898f08bdcc825f6f8d44379f8 100644 (file)
@@ -1236,6 +1236,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
         } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
           for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i)
             if (SI->getSuccessor(i) == BB) {
+              BB->removePredecessor(SI->getParent());
               SI->removeCase(i);
               --i; --e;
               Changed = true;
@@ -1263,6 +1264,12 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
               SI->setSuccessor(0, MaxBlock);
               Changed = true;
 
+              // If MaxBlock has phinodes in it, remove MaxPop-1 entries from
+              // it.
+              if (isa<PHINode>(MaxBlock->begin()))
+                for (unsigned i = 0; i != MaxPop-1; ++i)
+                  MaxBlock->removePredecessor(SI->getParent());
+
               for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i)
                 if (SI->getSuccessor(i) == MaxBlock) {
                   SI->removeCase(i);