[PATCH] D34185: [Parser][ObjC] Avoid crashing when skipping to EOF while parsing an ObjC interface/implementation
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 19 10:54:09 PDT 2017
This revision was automatically updated to reflect the committed changes.
arphaman marked an inline comment as done.
Closed by commit rL305719: [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods (authored by arphaman).
Changed prior to commit:
https://reviews.llvm.org/D34185?vs=103013&id=103075#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34185
Files:
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
Index: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
===================================================================
--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
+
+ at interface ClassA
+
+- (void)fileExistsAtPath:(int)x;
+
+ at end
+
+ at interface ClassB
+
+ at end
+
+ at implementation ClassB // expected-note {{implementation started here}}
+
+- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
+ mgr fileExistsAtPath:0
+} // expected-error {{expected ']'}}
+
+ at implementation ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}} // expected-warning {{cannot find interface declaration for 'ClassC'}}
+
+ at end
Index: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
===================================================================
--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
+
+ at interface ClassA
+
+- (void)fileExistsAtPath:(int)x;
+
+ at end
+
+ at interface ClassB
+
+ at end
+
+ at implementation ClassB // expected-note {{implementation started here}}
+
+- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
+ mgr fileExistsAtPath:0
+} // expected-error {{expected ']'}}
+
+ at interface ClassC // expected-error {{missing '@end'}} // expected-error {{expected '}'}}
+
+ at end
Index: cfe/trunk/lib/Parse/ParseObjc.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp
+++ cfe/trunk/lib/Parse/ParseObjc.cpp
@@ -3627,6 +3627,14 @@
SourceLocation OrigLoc = Tok.getLocation();
assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
+ // Store an artificial EOF token to ensure that we don't run off the end of
+ // the method's body when we come to parse it.
+ Token Eof;
+ Eof.startToken();
+ Eof.setKind(tok::eof);
+ Eof.setEofData(MCDecl);
+ Eof.setLocation(OrigLoc);
+ LM.Toks.push_back(Eof);
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
LM.Toks.push_back(Tok);
@@ -3658,7 +3666,7 @@
Actions.ActOnDefaultCtorInitializers(MCDecl);
ParseFunctionStatementBody(MCDecl, BodyScope);
}
-
+
if (Tok.getLocation() != OrigLoc) {
// Due to parsing error, we either went over the cached tokens or
// there are still cached tokens left. If it's the latter case skip the
@@ -3670,4 +3678,6 @@
while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
ConsumeAnyToken();
}
+ // Clean up the remaining EOF token.
+ ConsumeAnyToken();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34185.103075.patch
Type: text/x-patch
Size: 2765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170619/e365d05b/attachment-0001.bin>
More information about the cfe-commits
mailing list