fix some problems handling stmtexprs with labels (PR2374), and 
improve 'expression unused' diagnostics for stmtexprs.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54098 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 25a86fa..bb5ed50 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2334,9 +2334,15 @@
   // as the type of the stmtexpr.
   QualType Ty = Context.VoidTy;
   
-  if (!Compound->body_empty())
-    if (Expr *LastExpr = dyn_cast<Expr>(Compound->body_back()))
+  if (!Compound->body_empty()) {
+    Stmt *LastStmt = Compound->body_back();
+    // If LastStmt is a label, skip down through into the body.
+    while (LabelStmt *Label = dyn_cast<LabelStmt>(LastStmt))
+      LastStmt = Label->getSubStmt();
+    
+    if (Expr *LastExpr = dyn_cast<Expr>(LastStmt))
       Ty = LastExpr->getType();
+  }
   
   return new StmtExpr(Compound, Ty, LPLoc, RPLoc);
 }