Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp	(revision 148198)
+++ lib/CodeGen/CGStmt.cpp	(working copy)
@@ -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);
Index: test/CodeGenCXX/switch-case-folding.cpp
===================================================================
--- test/CodeGenCXX/switch-case-folding.cpp	(revision 0)
+++ test/CodeGenCXX/switch-case-folding.cpp	(working copy)
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -emit-llvm-only
+// CHECK that we don't crash.
+
+int main(void){
+	int x = 12;
+	// Make sure we don't crash when constant folding the case 4
+	// statement due to the case 5 statement contained in the do loop
+	switch (4) {
+		case 4: do { case 5: x++;} while (x < 100);
+	}
+	return x;
+}
