]> granicus.if.org Git - clang/commitdiff
Fixes a crash during constant folding of a switch and case
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Jan 2012 17:35:57 +0000 (17:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Jan 2012 17:35:57 +0000 (17:35 +0000)
statement which has an unscoped case inside it.
Patch by Aaron Ballman

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

lib/CodeGen/CGStmt.cpp

index 594281d15e88a3d43e697659bfb4a0921e8d2f9e..ee4a272ea8837e8c67f05302e1cd8c7fa72b47d9 100644 (file)
@@ -878,6 +878,16 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {
 }
 
 void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
+  // If there is no enclosing switch instance that we're aware of, then this
+  // case statement and its block can be elided.  This situation only happens
+  // when we've constant-folded the switch, are emitting the constant case,
+  // and part of the constant case includes another case statement.  For 
+  // instance: switch (4) { case 4: do { case 5: } while (1); }
+  if (!SwitchInsn) {
+    EmitStmt(S.getSubStmt());
+    return;
+  }
+
   // Handle case ranges.
   if (S.getRHS()) {
     EmitCaseStmtRange(S);