[cfe-commits] r128979 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/Parser/expressions.c

John McCall rjmccall at apple.com
Tue Apr 5 19:35:26 PDT 2011


Author: rjmccall
Date: Tue Apr  5 21:35:25 2011
New Revision: 128979

URL: http://llvm.org/viewvc/llvm-project?rev=128979&view=rev
Log:
Diagnose a missing ')' on what looks like a statement expression.
A situation where we can get an invalid ExprResult without an error.
Fixes PR8394.  Patch by Justin Bogner!


Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/Parser/expressions.c

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=128979&r1=128978&r2=128979&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Apr  5 21:35:25 2011
@@ -1631,6 +1631,9 @@
     ConsumeCodeCompletionToken();
     return ExprError();
   }
+
+  // None of these cases should fall through with an invalid Result
+  // unless they've already reported an error.
   
   if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
     Diag(Tok, diag::ext_gnu_statement_expr);
@@ -1639,7 +1642,7 @@
     ExprType = CompoundStmt;
 
     // If the substmt parsed correctly, build the AST node.
-    if (!Stmt.isInvalid() && Tok.is(tok::r_paren))
+    if (!Stmt.isInvalid())
       Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.take(), Tok.getLocation());
 
   } else if (ExprType >= CompoundLiteral &&
@@ -1737,6 +1740,8 @@
     
     Result = ParseExpression();
     ExprType = SimpleExpr;
+
+    // Don't build a paren expression unless we actually match a ')'.
     if (!Result.isInvalid() && Tok.is(tok::r_paren))
       Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.take());
   }

Modified: cfe/trunk/test/Parser/expressions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/expressions.c?rev=128979&r1=128978&r2=128979&view=diff
==============================================================================
--- cfe/trunk/test/Parser/expressions.c (original)
+++ cfe/trunk/test/Parser/expressions.c Tue Apr  5 21:35:25 2011
@@ -51,3 +51,9 @@
                test5(1)
                  ; // expected-error {{expected ')'}}
 }
+
+// PR8394
+void test7() {
+    ({} // expected-note {{to match}}
+    ;   // expected-error {{expected ')'}}
+}





More information about the cfe-commits mailing list