<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: arphaman<br class="">Date: Mon Jun 19 12:53:21 2017<br class="">New Revision: 305719<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=305719&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=305719&view=rev</a><br class="">Log:<br class="">[Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods<br class=""><br class="">This change avoid a crash that occurred when skipping to EOF while parsing an<br class="">ObjC interface/implementation.<br class=""><br class=""><a href="rdar://31963299" class="">rdar://31963299</a><br class=""><br class="">Differential Revision: https://reviews.llvm.org/D34185<br class=""><br class="">Added:<br class="">    cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m<br class="">    cfe/trunk/test/Parser/objc-at-interface-eof-crash.m<br class="">Modified:<br class="">    cfe/trunk/lib/Parse/ParseObjc.cpp<br class=""><br class="">Modified: cfe/trunk/lib/Parse/ParseObjc.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=305719&r1=305718&r2=305719&view=diff<br class="">==============================================================================<br class="">--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)<br class="">+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017<br class="">@@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le<br class="">   SourceLocation OrigLoc = Tok.getLocation();<br class=""><br class="">   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");<br class="">+  // Store an artificial EOF token to ensure that we don't run off the end of<br class="">+  // the method's body when we come to parse it.<br class="">+  Token Eof;<br class="">+  Eof.startToken();<br class="">+  Eof.setKind(tok::eof);<br class="">+  Eof.setEofData(MCDecl);<br class="">+  Eof.setLocation(OrigLoc);<br class="">+  LM.Toks.push_back(Eof);<br class="">   // Append the current token at the end of the new token stream so that it<br class="">   // doesn't get lost.<br class="">   LM.Toks.push_back(Tok);<br class="">@@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le<br class="">       Actions.ActOnDefaultCtorInitializers(MCDecl);<br class="">     ParseFunctionStatementBody(MCDecl, BodyScope);<br class="">   }<br class="">-  <br class="">+<br class="">   if (Tok.getLocation() != OrigLoc) {<br class="">     // Due to parsing error, we either went over the cached tokens or<br class="">     // there are still cached tokens left. If it's the latter case skip the<br class="">@@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le<br class="">       while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))<br class="">         ConsumeAnyToken();<br class="">   }<br class="">+  // Clean up the remaining EOF token.<br class="">+  ConsumeAnyToken();<br class=""> }<br class=""><br class="">Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m<br class="">URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305719&view=auto<br class="">==============================================================================<br class="">--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)<br class="">+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19 12:53:21 2017<br class="">@@ -0,0 +1,21 @@<br class="">+// RUN: %clang_cc1 -verify -Wno-objc-root-class %s<br class="">+<br class="">+@interface ClassA<br class="">+<br class="">+- (void)fileExistsAtPath:(int)x;<br class="">+<br class="">+@end<br class="">+<br class="">+@interface ClassB<br class="">+<br class="">+@end<br class="">+<br class="">+@implementation ClassB // expected-note {{implementation started here}}<br class="">+<br class="">+- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}<br class="">+  mgr fileExistsAtPath:0<br class="">+} // expected-error {{expected ']'}}<br class="">+<br class="">+@implementation ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}} // expected-warning {{cannot find interface declaration for 'ClassC'}}<br class=""></div></div></blockquote><div><br class=""></div><div>I believe you can split these expectations over multiple lines.  Something like this seems more readable:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><font face="Menlo" class="">@implementation ClassC                 \</font></div><div><font face="Menlo" class="">  // expected-error {{missing '@end'}} \</font></div><div><font face="Menlo" class="">  // expected-error {{expected '}'}}   \</font></div><div><font face="Menlo" class="">  // expected-warning {{cannot find interface declaration for 'ClassC'}}</font></div></div></blockquote><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div class="">+<br class="">+@end<br class=""><br class="">Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305719&view=auto" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305719&view=auto</a><br class="">==============================================================================<br class="">--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)<br class="">+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19 12:53:21 2017<br class="">@@ -0,0 +1,21 @@<br class="">+// RUN: %clang_cc1 -verify -Wno-objc-root-class %s<br class="">+<br class="">+@interface ClassA<br class="">+<br class="">+- (void)fileExistsAtPath:(int)x;<br class="">+<br class="">+@end<br class="">+<br class="">+@interface ClassB<br class="">+<br class="">+@end<br class="">+<br class="">+@implementation ClassB // expected-note {{implementation started here}}<br class="">+<br class="">+- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}<br class="">+  mgr fileExistsAtPath:0<br class="">+} // expected-error {{expected ']'}}<br class="">+<br class="">+@interface ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}}<br class=""></div></div></blockquote><div><br class=""></div><div>Same recommendation as above.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">+<br class="">+@end<br class=""><br class=""><br class="">_______________________________________________<br class="">cfe-commits mailing list<br class=""><a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits<br class=""></div></div></blockquote></div><br class=""></body></html>