aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-07-17 15:14:47 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-07-17 15:14:47 +0000
commit71adc5b587e4612e23d5ba234967b77a5f74b773 (patch)
tree27e64df0ef37c3b1bcea2d8f08ce6a28f6faeb6d
parenta555f2be4fce6edc8ab25eef508f21ed1e2d5dae (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160364 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp8
-rw-r--r--test/CodeGenCXX/pragma-visibility.cpp20
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 342acf825b..4041ccf9d3 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -8880,10 +8880,6 @@ CreateNewDecl:
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 @@ CreateNewDecl:
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;
}
diff --git a/test/CodeGenCXX/pragma-visibility.cpp b/test/CodeGenCXX/pragma-visibility.cpp
index 9b54a1813c..11a38c1d5f 100644
--- a/test/CodeGenCXX/pragma-visibility.cpp
+++ b/test/CodeGenCXX/pragma-visibility.cpp
@@ -52,3 +52,23 @@ namespace n __attribute((visibility("default"))) {
// 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
+}