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

Benjamin Kramer benny.kra at googlemail.com
Sun Mar 29 12:25:07 PDT 2015


Author: d0k
Date: Sun Mar 29 14:25:07 2015
New Revision: 233499

URL: http://llvm.org/viewvc/llvm-project?rev=233499&view=rev
Log:
[parse] Don't crash on alternative operator spellings from macros in c++11 attributes.

Found by afl-fuzz.

Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/cxx0x-attributes.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=233499&r1=233498&r2=233499&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sun Mar 29 14:25:07 2015
@@ -3527,7 +3527,9 @@ IdentifierInfo *Parser::TryParseCXX11Att
     // 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);

Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=233499&r1=233498&r2=233499&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Sun Mar 29 14:25:07 2015
@@ -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}}





More information about the cfe-commits mailing list