diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-03-30 22:14:32 +0000 | 
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-03-30 22:14:32 +0000 | 
| commit | 998d51b98f3716b5109d666243f9e0d69c9963dc (patch) | |
| tree | 785a2383291ca763c2519e9d7b17e2dc05507e8d /clang/lib/Parse | |
| parent | 57c644f926fea024c81160f201c4f5c2aeed0fb5 (diff) | |
| download | bcm5719-llvm-998d51b98f3716b5109d666243f9e0d69c9963dc.tar.gz bcm5719-llvm-998d51b98f3716b5109d666243f9e0d69c9963dc.zip  | |
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.
llvm-svn: 99939
Diffstat (limited to 'clang/lib/Parse')
| -rw-r--r-- | clang/lib/Parse/ParseCXXInlineMethods.cpp | 12 | 
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp index f1e639c2957..44a14c33159 100644 --- a/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -122,6 +122,9 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {        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 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {          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;        }  | 

