[cfe-commits] r160364 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGenCXX/pragma-visibility.cpp

Rafael Espindola rafael.espindola at gmail.com
Tue Jul 17 08:14:48 PDT 2012


Author: rafael
Date: Tue Jul 17 10:14:47 2012
New Revision: 160364

URL: http://llvm.org/viewvc/llvm-project?rev=160364&view=rev
Log:
Merge visibility from previous decls before looking at visibility pragma. This
is a bit fuzzy, but matches gcc behavior and existing code bases seem to
depend on it.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenCXX/pragma-visibility.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=160364&r1=160363&r2=160364&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jul 17 10:14:47 2012
@@ -8880,10 +8880,6 @@
   if (Attr)
     ProcessDeclAttributeList(S, New, Attr);
 
-  // If there's a #pragma GCC visibility in scope, set the visibility of this
-  // record.
-  AddPushedVisibilityAttribute(New);
-
   // If we're declaring or defining a tag in function prototype scope
   // in C, note that this type can only be used within the function.
   if (Name && S->isFunctionPrototypeScope() && !getLangOpts().CPlusPlus)
@@ -8946,6 +8942,10 @@
   if (PrevDecl)
     mergeDeclAttributes(New, PrevDecl);
 
+  // If there's a #pragma GCC visibility in scope, set the visibility of this
+  // record.
+  AddPushedVisibilityAttribute(New);
+
   OwnedDecl = true;
   return New;
 }

Modified: cfe/trunk/test/CodeGenCXX/pragma-visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pragma-visibility.cpp?rev=160364&r1=160363&r2=160364&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pragma-visibility.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/pragma-visibility.cpp Tue Jul 17 10:14:47 2012
@@ -52,3 +52,23 @@
   // CHECK: define hidden void @_ZN1n1gEv
 #pragma GCC visibility pop
 }
+
+namespace test2 {
+#pragma GCC visibility push(default)
+#pragma GCC visibility push(hidden)
+  struct foo { // foo is hidden
+  };
+#pragma GCC visibility pop
+  struct foo; // declaration is ok, we ignore the default in the stack
+  template<typename T>
+  struct bar { // bar is default
+    static void f(){}
+  };
+#pragma GCC visibility pop
+  void zed() {
+    bar<foo>::f();
+    bar<int>::f();
+  }
+  // CHECK: define linkonce_odr hidden void @_ZN5test23barINS_3fooEE1fEv
+  // CHECK: define linkonce_odr void @_ZN5test23barIiE1fEv
+}





More information about the cfe-commits mailing list