diff options
author | Dale Johannesen <dalej@apple.com> | 2008-05-23 17:19:02 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2008-05-23 17:19:02 +0000 |
commit | 679860e31bd7b8f043ba1ccdc5990cb9bafd9055 (patch) | |
tree | cd321e181bad56287ce8ff9cc0e0d977d3669803 | |
parent | b737a64a853edaa2dc30182611ab18f1cc6a2491 (diff) |
Rewrite a loop to avoid using iterators pointing to
elements that have been erased. Based on a patch
by Nicolas Capens.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51485 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index e935898f19..e67339ab38 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -529,18 +529,20 @@ unsigned BranchFolder::ComputeSameTails(unsigned CurHash, void BranchFolder::RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB, MachineBasicBlock* PredBB) { - for (MPIterator CurMPIter = prior(MergePotentials.end()), - B = MergePotentials.begin(); + MPIterator CurMPIter, B; + for (CurMPIter = prior(MergePotentials.end()), B = MergePotentials.begin(); CurMPIter->first==CurHash; --CurMPIter) { // Put the unconditional branch back, if we need one. MachineBasicBlock *CurMBB = CurMPIter->second; if (SuccBB && CurMBB != PredBB) FixTail(CurMBB, SuccBB, TII); - MergePotentials.erase(CurMPIter); - if (CurMPIter==B) + if (CurMPIter==B) break; } + if (CurMPIter->first!=CurHash) + CurMPIter++; + MergePotentials.erase(CurMPIter, MergePotentials.end()); } /// CreateCommonTailOnlyBlock - None of the blocks to be tail-merged consist |