SDAGBuilder: Avoid iterator invalidation harder.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 27 May 2012 09:44:52 +0000 (09:44 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 27 May 2012 09:44:52 +0000 (09:44 +0000)
vector.begin()-1 is invalid too.

llvm-svn: 157525

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

index f8cbcaa..1330a26 100644 (file)
@@ -1991,7 +1991,7 @@ bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
     // The last case block won't fall through into 'NextBlock' if we emit the
     // branches in this order.  See if rearranging a case value would help.
     // We start at the bottom as it's the case with the least weight.
-    for (CaseItr I = CR.Range.second-2, E = CR.Range.first-1; I != E; --I) {
+    for (CaseItr I = CR.Range.second-2, E = CR.Range.first; I >= E; --I) {
       if (I->BB == NextBlock) {
         std::swap(*I, BackCase);
         break;