r197082 - 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.

Aaron Ballman aaron at aaronballman.com
Wed Dec 11 14:27:44 PST 2013


Author: aaronballman
Date: Wed Dec 11 16:27:44 2013
New Revision: 197082

URL: http://llvm.org/viewvc/llvm-project?rev=197082&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/AttributeList.cpp
    cfe/trunk/test/Sema/MicrosoftCompatibility.c
    cfe/trunk/test/SemaCXX/attr-cxx0x.cpp

Modified: cfe/trunk/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=197082&r1=197081&r2=197082&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AttributeList.cpp (original)
+++ cfe/trunk/lib/Sema/AttributeList.cpp Wed Dec 11 16:27:44 2013
@@ -121,21 +121,25 @@ AttributeList::Kind AttributeList::getKi
                                            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 {

Modified: cfe/trunk/test/Sema/MicrosoftCompatibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftCompatibility.c?rev=197082&r1=197081&r2=197082&view=diff
==============================================================================
--- cfe/trunk/test/Sema/MicrosoftCompatibility.c (original)
+++ cfe/trunk/test/Sema/MicrosoftCompatibility.c Wed Dec 11 16:27:44 2013
@@ -19,3 +19,5 @@ __declspec(align(32768)) struct S1 { int
 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}} */

Modified: cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cxx0x.cpp?rev=197082&r1=197081&r2=197082&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-cxx0x.cpp Wed Dec 11 16:27:44 2013
@@ -45,3 +45,6 @@ static_assert(alignof(align_class_temp_p
 static_assert(alignof(outer<int,char>::inner<double,short>) == 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);





More information about the cfe-commits mailing list