From: Benjamin Kramer Date: Sun, 29 Mar 2015 19:25:07 +0000 (+0000) Subject: [parse] Don't crash on alternative operator spellings from macros in c++11 attributes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8996b3f58e7b3866dbdb12eca1183c56a5f9806;p=clang [parse] Don't crash on alternative operator spellings from macros in c++11 attributes. Found by afl-fuzz. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233499 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index ec19f35253..5c1a7bb3cf 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -3527,7 +3527,9 @@ IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) { // Alternative tokens do not have identifier info, but their spelling // starts with an alphabetical character. 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])) { Loc = ConsumeToken(); return &PP.getIdentifierTable().get(Spelling); diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp index 33987f94c2..7eec5761ea 100644 --- a/test/Parser/cxx0x-attributes.cpp +++ b/test/Parser/cxx0x-attributes.cpp @@ -346,3 +346,10 @@ namespace { deprecated ]] 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}}