]> granicus.if.org Git - clang/commitdiff
No longer accepting attribute spellings with prefix and suffix underscores except...
authorAaron Ballman <aaron@aaronballman.com>
Wed, 11 Dec 2013 22:27:44 +0000 (22:27 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 11 Dec 2013 22:27:44 +0000 (22:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197082 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AttributeList.cpp
test/Sema/MicrosoftCompatibility.c
test/SemaCXX/attr-cxx0x.cpp

index 023069c35b8a1c4d5971a1952a9e532a5fb9845d..b8ac7ce1af5570018a54f9175122342b46596bed 100644 (file)
@@ -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 {
index 6330c15667036d67be60455ea882f009ca66e3f7..cc18583f6f9ca68ed07b87f98e6ace86ab3f3201 100644 (file)
@@ -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}} */
index e24e12e50c4e4b974b4d6f0be34910da4d4f45be..02d9dc912917b754a5126f4a915258ddd513972c 100644 (file)
@@ -45,3 +45,6 @@ static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's
 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);