r222400 - PR21531: fix crash on invalid with unexpanded pack in case value.

Richard Smith richard-llvm at metafoo.co.uk
Wed Nov 19 17:24:12 PST 2014


Author: rsmith
Date: Wed Nov 19 19:24:12 2014
New Revision: 222400

URL: http://llvm.org/viewvc/llvm-project?rev=222400&view=rev
Log:
PR21531: fix crash on invalid with unexpanded pack in case value.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=222400&r1=222399&r2=222400&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Nov 19 19:24:12 2014
@@ -388,14 +388,19 @@ Sema::ActOnCaseStmt(SourceLocation CaseL
     }
   }
 
-  LHSVal = ActOnFinishFullExpr(LHSVal, LHSVal->getExprLoc(), false,
-                               getLangOpts().CPlusPlus11).get();
-  if (RHSVal)
-    RHSVal = ActOnFinishFullExpr(RHSVal, RHSVal->getExprLoc(), false,
-                                 getLangOpts().CPlusPlus11).get();
+  auto LHS = ActOnFinishFullExpr(LHSVal, LHSVal->getExprLoc(), false,
+                                 getLangOpts().CPlusPlus11);
+  if (LHS.isInvalid())
+    return StmtError();
 
-  CaseStmt *CS = new (Context) CaseStmt(LHSVal, RHSVal, CaseLoc, DotDotDotLoc,
-                                        ColonLoc);
+  auto RHS = RHSVal ? ActOnFinishFullExpr(RHSVal, RHSVal->getExprLoc(), false,
+                                          getLangOpts().CPlusPlus11)
+                    : ExprResult();
+  if (RHS.isInvalid())
+    return StmtError();
+
+  CaseStmt *CS = new (Context)
+      CaseStmt(LHS.get(), RHS.get(), CaseLoc, DotDotDotLoc, ColonLoc);
   getCurFunction()->SwitchStack.back()->addSwitchCase(CS);
   return CS;
 }

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp?rev=222400&r1=222399&r2=222400&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p5.cpp Wed Nov 19 19:24:12 2014
@@ -354,6 +354,7 @@ void test_unexpanded_exprs(Types ...valu
   for (auto t : values) { } // expected-error{{expression contains unexpanded parameter pack 'values'}}
 
   switch (values) { } // expected-error{{expression contains unexpanded parameter pack 'values'}}
+  switch (0) { case 0: case values: ; } // expected-error{{expression contains unexpanded parameter pack 'values'}}
 
   do { } while (values); // expected-error{{expression contains unexpanded parameter pack 'values'}}
 





More information about the cfe-commits mailing list