[cfe-commits] r156016 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/Sema/attr-visibility.c

Rafael Espindola rafael.espindola at gmail.com
Wed May 2 13:36:57 PDT 2012


Author: rafael
Date: Wed May  2 15:36:57 2012
New Revision: 156016

URL: http://llvm.org/viewvc/llvm-project?rev=156016&view=rev
Log:
Walk the decls looking for the last one that has an attribute. We do have to walk
them, otherwise we cannot produce an error for both

struct HIDDEN test4; // canonical
struct test4;
struct DEFAULT test4;

and

struct test5; // canonical
struct HIDDEN test5;
struct DEFAULT test5;

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/attr-visibility.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=156016&r1=156015&r2=156016&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed May  2 15:36:57 2012
@@ -1757,13 +1757,16 @@
     return;
   }
 
-  Decl *PrevDecl;
-  if (isa<FunctionDecl>(D))
-    PrevDecl = D->getMostRecentDecl()->getPreviousDecl();
-  else
-    PrevDecl = D->getCanonicalDecl();
+  // Find the last Decl that has an attribute.
+  VisibilityAttr *PrevAttr;
+  assert(D->redecls_begin() == D);
+  for (Decl::redecl_iterator I = D->redecls_begin(), E = D->redecls_end();
+       I != E; ++I) {
+    PrevAttr = I->getAttr<VisibilityAttr>() ;
+    if (PrevAttr)
+      break;
+  }
 
-  VisibilityAttr *PrevAttr = PrevDecl ? PrevDecl->getAttr<VisibilityAttr>() : 0;
   if (PrevAttr) {
     VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
     if (PrevVisibility != type) {

Modified: cfe/trunk/test/Sema/attr-visibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-visibility.c?rev=156016&r1=156015&r2=156016&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-visibility.c (original)
+++ cfe/trunk/test/Sema/attr-visibility.c Wed May  2 15:36:57 2012
@@ -10,3 +10,7 @@
 struct __attribute__((visibility("hidden"))) test4; // expected-note {{previous attribute is here}}
 struct test4;
 struct __attribute__((visibility("default"))) test4; // expected-error {{visibility does not match previous declaration}}
+
+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}}





More information about the cfe-commits mailing list