diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2013-12-11 22:27:44 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2013-12-11 22:27:44 +0000 |
| commit | c698809955b99ed1a42a6601a2a2887273452a44 (patch) | |
| tree | 2b5057c1e05d599e803879fb37581fa4df92b322 /clang/lib/Sema/AttributeList.cpp | |
| parent | 1bab70580dc15947dcfad2184999809f56b8e259 (diff) | |
| download | bcm5719-llvm-c698809955b99ed1a42a6601a2a2887273452a44.tar.gz bcm5719-llvm-c698809955b99ed1a42a6601a2a2887273452a44.zip | |
No longer accepting attribute spellings with prefix and suffix underscores except for GNU attributes, or C++11-style attributes in the GNU namespace. This prevents attributes such as __declspec(__dllexport__) or [[__noreturn__]] from being treated as known attributes.
llvm-svn: 197082
Diffstat (limited to 'clang/lib/Sema/AttributeList.cpp')
| -rw-r--r-- | clang/lib/Sema/AttributeList.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/clang/lib/Sema/AttributeList.cpp b/clang/lib/Sema/AttributeList.cpp index 023069c35b8..b8ac7ce1af5 100644 --- a/clang/lib/Sema/AttributeList.cpp +++ b/clang/lib/Sema/AttributeList.cpp @@ -121,21 +121,25 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name, Syntax SyntaxUsed) { StringRef AttrName = Name->getName(); - // Normalize the attribute name, __foo__ becomes foo. - if (AttrName.size() >= 4 && AttrName.startswith("__") && + SmallString<64> FullName; + if (ScopeName) + FullName += ScopeName->getName(); + + // Normalize the attribute name, __foo__ becomes foo. This is only allowable + // for GNU attributes. + bool IsGNU = SyntaxUsed == AS_GNU || (SyntaxUsed == AS_CXX11 && + FullName.equals("gnu")); + if (IsGNU && AttrName.size() >= 4 && AttrName.startswith("__") && AttrName.endswith("__")) - AttrName = AttrName.substr(2, AttrName.size() - 4); + AttrName = AttrName.slice(2, AttrName.size() - 2); - SmallString<64> Buf; - if (ScopeName) - Buf += ScopeName->getName(); // Ensure that in the case of C++11 attributes, we look for '::foo' if it is // unscoped. if (ScopeName || SyntaxUsed == AS_CXX11) - Buf += "::"; - Buf += AttrName; + FullName += "::"; + FullName += AttrName; - return ::getAttrKind(Buf); + return ::getAttrKind(FullName); } unsigned AttributeList::getAttributeSpellingListIndex() const { |

