From 7fe0bb2b43090f80773f05501ee31087b6b262ef Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 22 Jan 2008 23:58:54 +0000 Subject: [PATCH] Fix an iterator invalidation issue. llvm-svn: 46263 --- llvm/lib/CodeGen/StrongPHIElimination.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/StrongPHIElimination.cpp b/llvm/lib/CodeGen/StrongPHIElimination.cpp index 5b80b94f3fcd..cdf827d50e6e 100644 --- a/llvm/lib/CodeGen/StrongPHIElimination.cpp +++ b/llvm/lib/CodeGen/StrongPHIElimination.cpp @@ -751,11 +751,17 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) { // FIXME: Insert last-minute copies // Remove PHIs - for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) + std::vector phis; + for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) { for (MachineBasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE; ++BI) if (BI->getOpcode() == TargetInstrInfo::PHI) - BI->eraseFromParent(); + phis.push_back(BI); + } + + for (std::vector::iterator I = phis.begin(), E = phis.end(); + I != E; ++I) + (*I)->eraseFromParent(); return false; }