Fix a bug compimling Ruby, fixing this testcase:
authorChris Lattner <sabre@nondot.org>
Thu, 5 May 2005 15:47:43 +0000 (15:47 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 5 May 2005 15:47:43 +0000 (15:47 +0000)
LowerSetJmp/2005-05-05-OldUses.ll

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

lib/Transforms/IPO/LowerSetJmp.cpp

index 266729d6ca515ec6a4b0ed451dd845353ea75173..3a86cb763ba4023a61f0f0e16b79aa4fd2616c1e 100644 (file)
@@ -272,9 +272,17 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
   else
     new UnwindInst(Inst);
 
-  // Remove all insts after the branch/unwind inst.
-  Inst->getParent()->getInstList().erase(Inst,
-                                       Inst->getParent()->getInstList().end());
+  // Remove all insts after the branch/unwind inst.  Go from back to front to
+  // avoid replaceAllUsesWith if possible.
+  BasicBlock *BB = Inst->getParent();
+  Instruction *Removed;
+  do {
+    Removed = &BB->back();
+    // If the removed instructions have any users, replace them now.
+    if (!Removed->use_empty())
+      Removed->replaceAllUsesWith(UndefValue::get(Removed->getType()));
+    Removed->eraseFromParent();
+  } while (Removed != Inst);
 
   ++LongJmpsTransformed;
 }