diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-07-26 05:41:31 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-07-26 05:41:31 +0000 |
commit | 24b283005db37b259c30673d384807fed16fcbe5 (patch) | |
tree | 49137f3b553966fbeded7d8ab10cdfc5fd64f272 /clang/lib/Parse/ParseDecl.cpp | |
parent | 1f30f5aef709c36e8b8fc9fbec84d8cc884f79d6 (diff) | |
download | bcm5719-llvm-24b283005db37b259c30673d384807fed16fcbe5.tar.gz bcm5719-llvm-24b283005db37b259c30673d384807fed16fcbe5.zip |
Parse: Don't crash on trailing whitespace before EOF
Parser::ParseDeclarationSpecifiers eagerly updates the source range of
the DeclSpec with the current token position. However, it might not
consume any more tokens.
Fix this by only setting the start of the range, not the end. This way
the SourceRange will be invalid if we don't consume any more tokens.
This fixes PR20413.
Differential Revision: http://reviews.llvm.org/D4646
llvm-svn: 214018
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 1bbc8943372..727915c5a6c 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2449,8 +2449,11 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, DeclSpecContext DSContext, LateParsedAttrList *LateAttrs) { if (DS.getSourceRange().isInvalid()) { + // Start the range at the current token but make the end of the range + // invalid. This will make the entire range invalid unless we successfully + // consume a token. DS.SetRangeStart(Tok.getLocation()); - DS.SetRangeEnd(Tok.getLocation()); + DS.SetRangeEnd(SourceLocation()); } bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level); |