From 891eecb040b26426fdb31499939eb1916ce6bf8d Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 30 Jul 2007 21:26:39 +0000 Subject: [PATCH] Avoid potential iterator invalidation problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40607 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVN.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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(); -- 2.34.1