From: Owen Anderson Date: Mon, 30 Jul 2007 21:26:39 +0000 (+0000) Subject: Avoid potential iterator invalidation problems. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=891eecb040b26426fdb31499939eb1916ce6bf8d;p=oota-llvm.git Avoid potential iterator invalidation problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40607 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index fee0eedcc77..42e9ee8900f 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -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::iterator I = toErase.begin(), E = toErase.end(); I != E; ++I) (*I)->eraseFromParent();