implement rdar://9289524 - case followed immediately by break results in empty IR block,
a -O0 code quality issue.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129652 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 7a1ce19..b8b2cd9 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -867,11 +867,25 @@
 }
 
 void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
+  // Handle case ranges.
   if (S.getRHS()) {
     EmitCaseStmtRange(S);
     return;
   }
 
+  // If the body of the case is just a 'break', try to not emit an empty block.
+  if (isa<BreakStmt>(S.getSubStmt())) {
+    JumpDest Block = BreakContinueStack.back().BreakBlock;
+    
+    // Only do this optimization if there are no cleanups that need emitting.
+    if (isObviouslyBranchWithoutCleanups(Block)) {
+      llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext());
+      SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), CaseVal),
+                          Block.getBlock());
+      return;
+    }
+  }
+  
   EmitBlock(createBasicBlock("sw.bb"));
   llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
   llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext());