[parse] Don't crash on alternative operator spellings from macros in c++11 attributes.

Found by afl-fuzz.

llvm-svn: 233499
This commit is contained in:
Benjamin Kramer 2015-03-29 19:25:07 +00:00
parent dcbe1213c8
commit 60be563f3d
2 changed files with 10 additions and 1 deletions

View File

@ -3527,7 +3527,9 @@ IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) {
// Alternative tokens do not have identifier info, but their spelling // Alternative tokens do not have identifier info, but their spelling
// starts with an alphabetical character. // starts with an alphabetical character.
SmallString<8> SpellingBuf; SmallString<8> SpellingBuf;
StringRef Spelling = PP.getSpelling(Tok.getLocation(), SpellingBuf); SourceLocation SpellingLoc =
PP.getSourceManager().getSpellingLoc(Tok.getLocation());
StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
if (isLetter(Spelling[0])) { if (isLetter(Spelling[0])) {
Loc = ConsumeToken(); Loc = ConsumeToken();
return &PP.getIdentifierTable().get(Spelling); return &PP.getIdentifierTable().get(Spelling);

View File

@ -346,3 +346,10 @@ namespace {
deprecated deprecated
]] void bad(); ]] void bad();
} }
#define attr_name bitand
#define attr_name_2(x) x
#define attr_name_3(x, y) x##y
[[attr_name, attr_name_2(bitor), attr_name_3(com, pl)]] int macro_attrs; // expected-warning {{unknown attribute 'compl' ignored}} \
expected-warning {{unknown attribute 'bitor' ignored}} \
expected-warning {{unknown attribute 'bitand' ignored}}