diff options
author | David Greene <greened@obbligato.org> | 2007-06-29 02:45:24 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2007-06-29 02:45:24 +0000 |
commit | 451d1a6ecd3e4d56abf17ec25c818c2fe3c25984 (patch) | |
tree | 87032df7deac842e4fac562253e715409a861efb | |
parent | 9feb7f5846cce0d40db9e4689f8178f5fa570bc3 (diff) | |
download | bcm5719-llvm-451d1a6ecd3e4d56abf17ec25c818c2fe3c25984.tar.gz bcm5719-llvm-451d1a6ecd3e4d56abf17ec25c818c2fe3c25984.zip |
Fix misue of iterator pointing to erased object. Uncovered by
_GLIBCXX_DEBUG.
llvm-svn: 37793
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineBasicBlock.h | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 6 |
3 files changed, 10 insertions, 9 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index fe8a0ab3005..df6e5a32a82 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -211,9 +211,9 @@ public: /// removeSuccessor - Remove specified successor from the successors list of /// this MachineBasicBlock. The Predecessors list of succ is automatically - /// updated. + /// updated. Return the iterator to the element after the one removed. /// - void removeSuccessor(succ_iterator I); + succ_iterator removeSuccessor(succ_iterator I); /// isSuccessor - Return true if the specified MBB is a successor of this /// block. diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index ad7d5fcc332..d0dcc708d06 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -978,17 +978,18 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { } // Iterate through all the predecessors, revectoring each in-turn. - MachineBasicBlock::pred_iterator PI = MBB->pred_begin(); + size_t PI = 0; bool DidChange = false; bool HasBranchToSelf = false; - while (PI != MBB->pred_end()) { - if (*PI == MBB) { + while(PI != MBB->pred_size()) { + MachineBasicBlock *PMBB = *(MBB->pred_begin() + PI); + if (PMBB == MBB) { // If this block has an uncond branch to itself, leave it. ++PI; HasBranchToSelf = true; } else { DidChange = true; - (*PI)->ReplaceUsesOfBlockWith(MBB, CurTBB); + PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB); } } diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index da062b1559e..ba428c5bdb3 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -176,10 +176,10 @@ void MachineBasicBlock::removeSuccessor(MachineBasicBlock *succ) { Successors.erase(I); } -void MachineBasicBlock::removeSuccessor(succ_iterator I) { +MachineBasicBlock::succ_iterator MachineBasicBlock::removeSuccessor(succ_iterator I) { assert(I != Successors.end() && "Not a current successor!"); (*I)->removePredecessor(this); - Successors.erase(I); + return(Successors.erase(I)); } void MachineBasicBlock::addPredecessor(MachineBasicBlock *pred) { @@ -273,7 +273,7 @@ bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA, ++SI; } else { // Otherwise, this is a superfluous edge, remove it. - removeSuccessor(SI); + SI = removeSuccessor(SI); MadeChange = true; } } |