From: Aaron Ballman Date: Wed, 11 Dec 2013 22:27:44 +0000 (+0000) Subject: No longer accepting attribute spellings with prefix and suffix underscores except... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=606069ed0596a77e9e669f7edeb0e317bed7858e;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197082 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp index 023069c35b..b8ac7ce1af 100644 --- a/lib/Sema/AttributeList.cpp +++ b/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 { diff --git a/test/Sema/MicrosoftCompatibility.c b/test/Sema/MicrosoftCompatibility.c index 6330c15667..cc18583f6f 100644 --- a/test/Sema/MicrosoftCompatibility.c +++ b/test/Sema/MicrosoftCompatibility.c @@ -19,3 +19,5 @@ __declspec(align(32768)) struct S1 { int a; } s; /* expected-error {{requested a struct __declspec(aligned) S2 {}; /* expected-warning {{unknown __declspec attribute 'aligned' ignored}} */ struct __declspec(appdomain) S3 {}; /* expected-warning {{__declspec attribute 'appdomain' is not supported}} */ + +__declspec(__noreturn__) void f7(void); /* expected-warning {{unknown __declspec attribute '__noreturn__' ignored}} */ diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index e24e12e50c..02d9dc9129 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -45,3 +45,6 @@ static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's static_assert(alignof(outer::inner) == alignof(int) * alignof(double), "template's alignment is wrong"); static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-error{{invalid application of 'alignof' to a function type}} + +[[__carries_dependency__]] // expected-warning{{unknown attribute '__carries_dependency__' ignored}} +void func(void);