From 1e2a12019fa858a304fcebe0a8db1181e8d8d890 Mon Sep 17 00:00:00 2001 From: David Greene Date: Fri, 29 Jun 2007 02:53:16 +0000 Subject: [PATCH] Fix reference to iterator invalidated by an erase operation. Uncovered by _GLIBCXX_DEBUG. llvm-svn: 37796 --- llvm/lib/Transforms/Utils/LoopSimplify.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp index 8a3e5251fd69..0a5de2b43ed7 100644 --- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp +++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp @@ -564,11 +564,12 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) { // Scan all of the loop children of L, moving them to OuterLoop if they are // not part of the inner loop. - for (Loop::iterator I = L->begin(); I != L->end(); ) - if (BlocksInL.count((*I)->getHeader())) + const std::vector &SubLoops = L->getSubLoops(); + for (size_t I = 0; I != SubLoops.size(); ) + if (BlocksInL.count(SubLoops[I]->getHeader())) ++I; // Loop remains in L else - NewOuter->addChildLoop(L->removeChildLoop(I)); + NewOuter->addChildLoop(L->removeChildLoop(SubLoops.begin() + I)); // Now that we know which blocks are in L and which need to be moved to // OuterLoop, move any blocks that need it. -- GitLab