Fix reference to cached end iterator invalidated by an erase operation.
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jun 2007 02:49:11 +0000 (02:49 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jun 2007 02:49:11 +0000 (02:49 +0000)
Uncovered by _GLIBCXX_DEBUG.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37795 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 224006106b2f323ef8290c664c4b9314d19539fc..6251d381be1b37b4940508a43c5794d2d7045a98 100644 (file)
@@ -1700,7 +1700,9 @@ unsigned SelectionDAGLowering::Clusterify(CaseVector& Cases,
 
   // Merge case into clusters
   if (Cases.size()>=2)
-    for (CaseItr I=Cases.begin(), J=++(Cases.begin()), E=Cases.end(); J!=E; ) {
+    // Cray [dag]: Must recompute end() each iteration because it may
+    // be invalidated by erase if we hold on to it
+    for (CaseItr I=Cases.begin(), J=++(Cases.begin()); J!=Cases.end(); ) {
       int64_t nextValue = cast<ConstantInt>(J->Low)->getSExtValue();
       int64_t currentValue = cast<ConstantInt>(I->High)->getSExtValue();
       MachineBasicBlock* nextBB = J->BB;