[cfe-commits] r148243 - /cfe/trunk/lib/CodeGen/CGStmt.cpp

Fariborz Jahanian fjahanian at apple.com
Mon Jan 16 09:35:58 PST 2012


Author: fjahanian
Date: Mon Jan 16 11:35:57 2012
New Revision: 148243

URL: http://llvm.org/viewvc/llvm-project?rev=148243&view=rev
Log:
Fixes a crash during constant folding of a switch and case 
statement which has an unscoped case inside it.
Patch by Aaron Ballman

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=148243&r1=148242&r2=148243&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Mon Jan 16 11:35:57 2012
@@ -878,6 +878,16 @@
 }
 
 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);





More information about the cfe-commits mailing list