On Jun 18, 2010, at 5:40 PM, Douglas Gregor wrote: > > On Jun 17, 2010, at 3:52 AM, Argiris Kirtzidis wrote: > >> Author: akirtzidis >> Date: Thu Jun 17 05:52:22 2010 >> New Revision: 106214 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=106214&view=rev >> Log: >> Make sure the caching mechanism in Parser::ParseLexedMethodDefs is robust >> against the parser reading too few tokens. >> >> Modified: >> cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp >> >> Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=106214&r1=106213&r2=106214&view=diff >> ============================================================================== >> --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original) >> +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Thu Jun 17 05:52:22 2010 >> @@ -216,8 +216,10 @@ >> 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 @@ >> >> 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(); >> + >> + } >> } > > I would sleep better at night if this while loop also had a > Tok.isNot(tok::eof) check.
Done on r106394. -Argiris _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
