]> granicus.if.org Git - clang/commitdiff
[Parser] Fix look ahead after EOF while parsing objc message and lambdas
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 31 May 2016 18:46:31 +0000 (18:46 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Tue, 31 May 2016 18:46:31 +0000 (18:46 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271314 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/Parser/objcxx11-messaging-and-lambda.mm [new file with mode: 0644]

index b569e7aeba13a323c7d8285a11f1677bd5093de0..b0740970d88d6f551973788dd50b98a86f9368d2 100644 (file)
@@ -739,8 +739,11 @@ ExprResult Parser::TryParseLambdaExpression() {
          && 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) ||        // [=
diff --git a/test/Parser/objcxx11-messaging-and-lambda.mm b/test/Parser/objcxx11-messaging-and-lambda.mm
new file mode 100644 (file)
index 0000000..002f3e9
--- /dev/null
@@ -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 '}'}}