On Mar 30, 2010, at 3:14 PM, Argiris Kirtzidis wrote: > Author: akirtzidis > Date: Tue Mar 30 17:14:32 2010 > New Revision: 99939 > > URL: http://llvm.org/viewvc/llvm-project?rev=99939&view=rev > Log: > When "delayed parsing" C++ default arguments, if there is an error, there may > be tokens left in the token stream > that will interfere (they will be parsed as if they are after the class' '}') > and a crash will occur because > the CachedTokens that holds them will be deleted while the lexer is still > using them. > > Make sure that the tokens of default args are removed from the token stream. > Fixes PR6647.
Isn't there the potential for having this same problem in ParseLexedMethodDefs, where we've cached the tokens for the function body? > Added: > cfe/trunk/test/Parser/cxx-default-args.cpp > 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=99939&r1=99938&r2=99939&view=diff > ============================================================================== > --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original) > +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Tue Mar 30 17:14:32 2010 > @@ -122,6 +122,9 @@ > Actions.ActOnDelayedCXXMethodParameter(CurScope, > LM.DefaultArgs[I].Param); > > if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) { > + // Save the current token position. > + SourceLocation origLoc = Tok.getLocation(); > + > // Parse the default argument from its saved token stream. > Toks->push_back(Tok); // So that the current token doesn't get lost > PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false); > @@ -139,6 +142,15 @@ > else > Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc, > move(DefArgResult)); > + > + assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, > + > Tok.getLocation()) && > + "ParseAssignmentExpression went over the default arg > tokens!"); > + // 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(); > + > delete Toks; > LM.DefaultArgs[I].Toks = 0; > } > > Added: cfe/trunk/test/Parser/cxx-default-args.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-default-args.cpp?rev=99939&view=auto > ============================================================================== > --- cfe/trunk/test/Parser/cxx-default-args.cpp (added) > +++ cfe/trunk/test/Parser/cxx-default-args.cpp Tue Mar 30 17:14:32 2010 > @@ -0,0 +1,9 @@ > +// RUN: %clang_cc1 -fsyntax-only -verify %s > + > +// PR6647 > +class C { > + // After the error, the rest of the tokens inside the default arg should be > + // skipped, avoiding a "expected ';' after class" after 'undecl'. > + void m(int x = undecl + 0); // expected-error {{use of undeclared > identifier 'undecl'}} > +}; > + > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
