diff options
author | David Greene <greened@obbligato.org> | 2008-04-02 18:24:46 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2008-04-02 18:24:46 +0000 |
commit | b561faaa2f882ad4fb164d0e80066d6bc3581fac (patch) | |
tree | 7d5f70963daea7c3130fa21056d1108bfe2affed | |
parent | 251fa15cb518dca9a3707f4bfb8dc4f3c0370f25 (diff) | |
download | external_llvm-b561faaa2f882ad4fb164d0e80066d6bc3581fac.zip external_llvm-b561faaa2f882ad4fb164d0e80066d6bc3581fac.tar.gz external_llvm-b561faaa2f882ad4fb164d0e80066d6bc3581fac.tar.bz2 |
Iterators folloring a SmallVector erased element are invalidated so
don't access cached iterators from after the erased element.
Re-apply 49056 with SmallVector support.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49106 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 8 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopIndexSplit.cpp | 10 |
2 files changed, 10 insertions, 8 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index a6b65dd..c2de17a 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -208,19 +208,23 @@ public: construct_range(Begin, End, Elt); } - void erase(iterator I) { + iterator erase(iterator I) { + iterator N = I; // Shift all elts down one. std::copy(I+1, End, I); // Drop the last elt. pop_back(); + return(N); } - void erase(iterator S, iterator E) { + iterator erase(iterator S, iterator E) { + iterator N = S; // Shift all elts down. iterator I = std::copy(E, End, S); // Drop the last elts. destroy_range(I, End); End = I; + return(N); } iterator insert(iterator I, const T &Elt) { diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 8053554..48b4535 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -232,8 +232,8 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { return false; // First see if it is possible to eliminate loop itself or not. - for (SmallVector<SplitInfo, 4>::iterator SI = SplitData.begin(), - E = SplitData.end(); SI != E;) { + for (SmallVector<SplitInfo, 4>::iterator SI = SplitData.begin(); + SI != SplitData.end();) { SplitInfo &SD = *SI; ICmpInst *CI = dyn_cast<ICmpInst>(SD.SplitCondition); if (SD.SplitCondition->getOpcode() == Instruction::And) { @@ -244,8 +244,7 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { return Changed; } else { SmallVector<SplitInfo, 4>::iterator Delete_SI = SI; - ++SI; - SplitData.erase(Delete_SI); + SI = SplitData.erase(Delete_SI); } } else if (CI && CI->getPredicate() == ICmpInst::ICMP_EQ) { @@ -256,8 +255,7 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { return Changed; } else { SmallVector<SplitInfo, 4>::iterator Delete_SI = SI; - ++SI; - SplitData.erase(Delete_SI); + SI = SplitData.erase(Delete_SI); } } else ++SI; |