diff --git a/lib/Transforms/Scalar/LoopInterchange.cpp b/lib/Transforms/Scalar/LoopInterchange.cpp index 75596786072..f584018299d 100644 --- a/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1012,8 +1012,8 @@ void LoopInterchangeTransform::restructureLoops(Loop *InnerLoop, LI->changeTopLevelLoop(OuterLoop, InnerLoop); } - for (Loop::iterator I = InnerLoop->begin(), E = InnerLoop->end(); I != E; ++I) - OuterLoop->addChildLoop(InnerLoop->removeChildLoop(I)); + while (!InnerLoop->empty()) + OuterLoop->addChildLoop(InnerLoop->removeChildLoop(InnerLoop->begin())); InnerLoop->addChildLoop(OuterLoop); }