SDAGBuilder: Don't create an invalid iterator when there is only one switch case.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 26 May 2012 21:19:12 +0000 (21:19 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 26 May 2012 21:19:12 +0000 (21:19 +0000)
Found by libstdc++'s debug mode.

llvm-svn: 157522

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

index 0d37c62..f8cbcaa 100644 (file)
@@ -1984,10 +1984,10 @@ bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
       }
     }
   }
-
   // Rearrange the case blocks so that the last one falls through if possible.
   Case &BackCase = *(CR.Range.second-1);
-  if (NextBlock && Default != NextBlock && BackCase.BB != NextBlock) {
+  if (Size > 1 &&
+      NextBlock && Default != NextBlock && BackCase.BB != NextBlock) {
     // 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.