summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-17 10:52:22 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-17 10:52:22 +0000
commite9b76afe4fb7008c75cec221d2a8992e5522334e (patch)
treeca9c9c4e93f7bbc9bbaa524ac949b1548cbd5208
parent355094ef06a3d47f0600e85744f6e995706b12d3 (diff)
downloadbcm5719-llvm-e9b76afe4fb7008c75cec221d2a8992e5522334e.tar.gz
bcm5719-llvm-e9b76afe4fb7008c75cec221d2a8992e5522334e.zip
Make sure the caching mechanism in Parser::ParseLexedMethodDefs is robust against the parser reading too few tokens.
llvm-svn: 106214
-rw-r--r--clang/lib/Parse/ParseCXXInlineMethods.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index fd231901a4c..e765a06087d 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -216,8 +216,10 @@ void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
Tok.getLocation()) &&
"ParseFunctionTryBlock went over the cached tokens!");
- assert(Tok.getLocation() == origLoc &&
- "ParseFunctionTryBlock left tokens in the token stream!");
+ // There could be leftover tokens (e.g. because of an error).
+ // Skip through until we reach the original token position.
+ while (Tok.getLocation() != origLoc)
+ ConsumeAnyToken();
continue;
}
if (Tok.is(tok::colon)) {
@@ -233,8 +235,18 @@ void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
ParseFunctionStatementBody(LM.D);
- // FIXME: We need to make sure the caching mechanism here is robust
- // against the parser reading too few token
+ 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)
+ ConsumeAnyToken();
+
+ }
}
for (unsigned I = 0, N = Class.NestedClasses.size(); I != N; ++I)
OpenPOWER on IntegriCloud