r271314 - [Parser] Fix look ahead after EOF while parsing objc message and lambdas

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 11:46:32 PDT 2016


Author: bruno
Date: Tue May 31 13:46:31 2016
New Revision: 271314

URL: http://llvm.org/viewvc/llvm-project?rev=271314&view=rev
Log:
[Parser] Fix look ahead after EOF while parsing objc message and lambdas

If a closing ')' isn't found for a macro instantiation inside a '[',
the next token is EOF, this leads to crashes if we try to look ahead of
that. This could be triggered whenever trying to parse lambdas or objs
message expressions.

Differential Revision: http://reviews.llvm.org/D20451

rdar://problem/25662647

Added:
    cfe/trunk/test/Parser/objcxx11-messaging-and-lambda.mm
Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=271314&r1=271313&r2=271314&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue May 31 13:46:31 2016
@@ -739,8 +739,11 @@ ExprResult Parser::TryParseLambdaExpress
          && Tok.is(tok::l_square)
          && "Not at the start of a possible lambda expression.");
 
-  const Token Next = NextToken(), After = GetLookAheadToken(2);
+  const Token Next = NextToken();
+  if (Next.is(tok::eof)) // Nothing else to lookup here...
+    return ExprEmpty();
 
+  const Token After = GetLookAheadToken(2);
   // If lookahead indicates this is a lambda...
   if (Next.is(tok::r_square) ||     // []
       Next.is(tok::equal) ||        // [=

Added: cfe/trunk/test/Parser/objcxx11-messaging-and-lambda.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objcxx11-messaging-and-lambda.mm?rev=271314&view=auto
==============================================================================
--- cfe/trunk/test/Parser/objcxx11-messaging-and-lambda.mm (added)
+++ cfe/trunk/test/Parser/objcxx11-messaging-and-lambda.mm Tue May 31 13:46:31 2016
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+#define OBJCLASS(name) // expected-note {{macro 'OBJCLASS' defined here}}
+
+class NSMutableData;
+
+NSMutableData *test() { // expected-note {{to match this '{'}}
+  NSMutableData *data = [[[OBJCLASS(NSMutableDataOBJCLASS( alloc] init] autorelease]; // expected-error {{unterminated function-like macro invocation}} \
+  // expected-error {{expected ';' at end of declaration}}
+  return data;
+} // expected-error {{expected expression}} expected-error {{expected '}'}}




More information about the cfe-commits mailing list