Avoid potential iterator invalidation problems.
authorOwen Anderson <resistor@mac.com>
Mon, 30 Jul 2007 21:26:39 +0000 (21:26 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 30 Jul 2007 21:26:39 +0000 (21:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp

index fee0eedcc770770bba0c7f16096954eac676f53d..42e9ee8900fcfa47abc51475647b79917bd2f87b 100644 (file)
@@ -895,11 +895,14 @@ bool GVN::runOnFunction(Function &F) {
       currAvail = availableOut[DI->getIDom()->getBlock()];
 
     for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
-         BI != BE; ++BI) {
+         BI != BE; ) {
       changed_function |= processInstruction(BI, currAvail, lastSeenLoad, toErase);
       
       NumGVNInstr += toErase.size();
       
+      // Avoid iterator invalidation
+      ++BI;
+      
       for (SmallVector<Instruction*, 4>::iterator I = toErase.begin(),
            E = toErase.end(); I != E; ++I)
         (*I)->eraseFromParent();