Avoid potential iterator invalidation problems.

llvm-svn: 40607
This commit is contained in:
Owen Anderson 2007-07-30 21:26:39 +00:00
parent 14fae50666
commit 850138157e
1 changed files with 4 additions and 1 deletions

View 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();