]> granicus.if.org Git - clang/commitdiff
[parse] Don't crash on alternative operator spellings from macros in c++11 attributes.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 19:25:07 +0000 (19:25 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 19:25:07 +0000 (19:25 +0000)
Found by afl-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233499 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDeclCXX.cpp
test/Parser/cxx0x-attributes.cpp

index ec19f352532fc91a1f0668d0b81eca0906a3af49..5c1a7bb3cfd85808610bd9c5d01c3a5de41ed40a 100644 (file)
@@ -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);
index 33987f94c2e6f4765a8213d3254d2b09d030ea81..7eec5761ea055d492e8bfa41442740ca1c406dba 100644 (file)
@@ -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}}