[cfe-commits] r154749 - in /cfe/trunk: lib/AST/Decl.cpp test/CodeGenCXX/visibility.cpp

Rafael Espindola rafael.espindola at gmail.com
Sat Apr 14 08:21:19 PDT 2012


Author: rafael
Date: Sat Apr 14 10:21:19 2012
New Revision: 154749

URL: http://llvm.org/viewvc/llvm-project?rev=154749&view=rev
Log:
Consider visibility attributes last, so that they take precedence.
I am working on a cleaner fix, but this gets the case in PR12552 passing.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/CodeGenCXX/visibility.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=154749&r1=154748&r2=154749&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Apr 14 10:21:19 2012
@@ -281,27 +281,6 @@
   LinkageInfo LV;
   LV.mergeVisibility(Context.getLangOpts().getVisibilityMode());
 
-  if (F.ConsiderVisibilityAttributes) {
-    if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
-      LV.setVisibility(*Vis, true);
-      F.ConsiderGlobalVisibility = false;
-    } else {
-      // If we're declared in a namespace with a visibility attribute,
-      // use that namespace's visibility, but don't call it explicit.
-      for (const DeclContext *DC = D->getDeclContext();
-           !isa<TranslationUnitDecl>(DC);
-           DC = DC->getParent()) {
-        const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
-        if (!ND) continue;
-        if (llvm::Optional<Visibility> Vis = ND->getExplicitVisibility()) {
-          LV.setVisibility(*Vis, true);
-          F.ConsiderGlobalVisibility = false;
-          break;
-        }
-      }
-    }
-  }
-
   // C++ [basic.link]p4:
 
   //   A name having namespace scope has external linkage if it is the
@@ -478,6 +457,27 @@
     return LinkageInfo::none();
   }
 
+  if (F.ConsiderVisibilityAttributes) {
+    if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
+      LV.setVisibility(*Vis, true);
+      F.ConsiderGlobalVisibility = false;
+    } else {
+      // If we're declared in a namespace with a visibility attribute,
+      // use that namespace's visibility, but don't call it explicit.
+      for (const DeclContext *DC = D->getDeclContext();
+           !isa<TranslationUnitDecl>(DC);
+           DC = DC->getParent()) {
+        const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
+        if (!ND) continue;
+        if (llvm::Optional<Visibility> Vis = ND->getExplicitVisibility()) {
+          LV.setVisibility(*Vis, true);
+          F.ConsiderGlobalVisibility = false;
+          break;
+        }
+      }
+    }
+  }
+
   // If we ended up with non-external linkage, visibility should
   // always be default.
   if (LV.linkage() != ExternalLinkage)

Modified: cfe/trunk/test/CodeGenCXX/visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/visibility.cpp?rev=154749&r1=154748&r2=154749&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/visibility.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/visibility.cpp Sat Apr 14 10:21:19 2012
@@ -28,6 +28,18 @@
   // CHECK-HIDDEN: @_ZN6test285myvecE = hidden global
 }
 
+namespace test29 {
+#pragma GCC visibility push(hidden)
+  struct RECT {
+    int top;
+  };
+  __attribute__ ((visibility ("default"))) extern RECT data_rect;
+  RECT data_rect = { -1};
+#pragma GCC visibility pop
+  // CHECK: @_ZN6test299data_rectE = global
+  // CHECK-HIDDEN: @_ZN6test299data_rectE = global
+}
+
 // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
 // CHECK: @_ZN5Test71aE = hidden global
 // CHECK: @_ZN5Test71bE = global





More information about the cfe-commits mailing list