[cfe-commits] r146814 - /cfe/trunk/lib/Parse/ParseObjc.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Dec 16 20:13:18 PST 2011
Author: akirtzidis
Date: Fri Dec 16 22:13:18 2011
New Revision: 146814
URL: http://llvm.org/viewvc/llvm-project?rev=146814&view=rev
Log:
After late parsing an objc method, make sure there are no leftover cached tokens,
because the memory associated with them is going to get released.
We also don't want them to affect later parsing.
(We do the same for C++ inline methods.)
The underlying cause for the leftover tokens is going to be addressed in the
next commit.
Couldn't get a test case for the crash though. rdar://10583033.
Modified:
cfe/trunk/lib/Parse/ParseObjc.cpp
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=146814&r1=146813&r2=146814&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Dec 16 22:13:18 2011
@@ -2564,7 +2564,10 @@
}
Decl *Parser::ParseLexedObjCMethodDefs(LexedMethod &LM) {
-
+
+ // Save the current token position.
+ SourceLocation OrigLoc = Tok.getLocation();
+
assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
@@ -2603,5 +2606,19 @@
// Leave the function body scope.
BodyScope.Exit();
- return Actions.ActOnFinishFunctionBody(MDecl, FnBody.take());
+ MDecl = Actions.ActOnFinishFunctionBody(MDecl, FnBody.take());
+
+ 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
+ // leftover tokens.
+ // Since this is an uncommon situation that should be avoided, use the
+ // expensive isBeforeInTranslationUnit call.
+ if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(),
+ OrigLoc))
+ while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
+ ConsumeAnyToken();
+ }
+
+ return MDecl;
}
More information about the cfe-commits
mailing list