[cfe-commits] r156343 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp lib/Sema/TargetAttributesSema.cpp test/Index/complete-with-annotations.cpp test/Sema/attr-availability.c test/Sema/attr-visibility.c test/Sema/dllimport-dllexport.c

Rafael Espindola rafael.espindola at gmail.com
Mon May 7 16:58:18 PDT 2012


Author: rafael
Date: Mon May  7 18:58:18 2012
New Revision: 156343

URL: http://llvm.org/viewvc/llvm-project?rev=156343&view=rev
Log:
Process attributes in the order they appear in the source code. This make clang
match gcc behavior for two conflicting visibilities in the same decl. It also
makes handling of dllimport/dllexport more natural.

As a bonus we now warn on the dllimport in

void __attribute__((dllimport)) foo13();
void __attribute__((dllexport)) foo13();

as does gcc.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/TargetAttributesSema.cpp
    cfe/trunk/test/Index/complete-with-annotations.cpp
    cfe/trunk/test/Sema/attr-availability.c
    cfe/trunk/test/Sema/attr-visibility.c
    cfe/trunk/test/Sema/dllimport-dllexport.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon May  7 18:58:18 2012
@@ -3986,8 +3986,12 @@
 void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
                                     const AttributeList *AttrList,
                                     bool NonInheritable, bool Inheritable) {
+  SmallVector<const AttributeList*, 4> attrs;
   for (const AttributeList* l = AttrList; l; l = l->getNext()) {
-    ProcessDeclAttribute(*this, S, D, *l, NonInheritable, Inheritable);
+    attrs.push_back(l);
+  }
+  for (int i = attrs.size() - 1; i >= 0; --i) {
+    ProcessDeclAttribute(*this, S, D, *attrs[i], NonInheritable, Inheritable);
   }
 
   // GCC accepts

Modified: cfe/trunk/lib/Sema/TargetAttributesSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TargetAttributesSema.cpp?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TargetAttributesSema.cpp (original)
+++ cfe/trunk/lib/Sema/TargetAttributesSema.cpp Mon May  7 18:58:18 2012
@@ -182,16 +182,6 @@
     return;
   }
 
-  // The attribute is also overridden by a subsequent declaration as dllexport.
-  // Warning is emitted.
-  for (AttributeList *nextAttr = Attr.getNext(); nextAttr;
-       nextAttr = nextAttr->getNext()) {
-    if (nextAttr->getKind() == AttributeList::AT_dllexport) {
-      S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
-      return;
-    }
-  }
-
   if (D->getAttr<DLLExportAttr>()) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
     return;
@@ -228,6 +218,11 @@
     return;
   }
 
+  if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) {
+    S.Diag(Import->getLocation(), diag::warn_attribute_ignored) << "dllimport";
+    D->dropAttr<DLLImportAttr>();
+  }
+
   D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
 }
 

Modified: cfe/trunk/test/Index/complete-with-annotations.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-with-annotations.cpp?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-with-annotations.cpp (original)
+++ cfe/trunk/test/Index/complete-with-annotations.cpp Mon May  7 18:58:18 2012
@@ -14,7 +14,7 @@
 }
 
 // CHECK: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34)
-// CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("three", "two", "one")
+// CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("one", "two", "three")
 // CHECK: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) ("some annotation")
 // CHECK: FieldDecl:{ResultType int}{TypedText member2} (35) ("another annotation", "some annotation")
 // CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (34)

Modified: cfe/trunk/test/Sema/attr-availability.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability.c?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-availability.c (original)
+++ cfe/trunk/test/Sema/attr-availability.c Mon May  7 18:58:18 2012
@@ -28,8 +28,8 @@
 void f4(int) __attribute__((availability(ios,deprecated=3.0)));
 void f4(int) __attribute__((availability(ios,introduced=4.0))); // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}}
 
-void f5(int) __attribute__((availability(ios,deprecated=3.0),  // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}}
-                            availability(ios,introduced=4.0)));
+void f5(int) __attribute__((availability(ios,deprecated=3.0),
+                            availability(ios,introduced=4.0)));  // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}}
 
 void f6(int) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{previous attribute is here}}
 void f6(int) __attribute__((availability(ios,deprecated=4.0))); // expected-warning {{availability does not match previous declaration}}

Modified: cfe/trunk/test/Sema/attr-visibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-visibility.c?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-visibility.c (original)
+++ cfe/trunk/test/Sema/attr-visibility.c Mon May  7 18:58:18 2012
@@ -14,3 +14,6 @@
 struct test5;
 struct __attribute__((visibility("hidden"))) test5; // expected-note {{previous attribute is here}}
 struct __attribute__((visibility("default"))) test5; // expected-error {{visibility does not match previous declaration}}
+
+void test6() __attribute__((visibility("hidden"), // expected-note {{previous attribute is here}}
+                            visibility("default"))); // expected-error {{visibility does not match previous declaration}}

Modified: cfe/trunk/test/Sema/dllimport-dllexport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport-dllexport.c?rev=156343&r1=156342&r2=156343&view=diff
==============================================================================
--- cfe/trunk/test/Sema/dllimport-dllexport.c (original)
+++ cfe/trunk/test/Sema/dllimport-dllexport.c Mon May  7 18:58:18 2012
@@ -35,3 +35,6 @@
 
 void __declspec(dllimport) foo12();
 void foo12(){} // expected-warning {{'foo12' redeclared without dllimport attribute: previous dllimport ignored}}
+
+void __attribute__((dllimport)) foo13(); // expected-warning{{dllimport attribute ignored}}
+void __attribute__((dllexport)) foo13();





More information about the cfe-commits mailing list