Fix the visibility of instantiations of static data members.
Fixes pr12835.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156897 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 21405d2..d31cf0f 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -633,9 +633,19 @@
llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const {
// Use the most recent declaration of a variable.
- if (const VarDecl *var = dyn_cast<VarDecl>(this))
- return getVisibilityOf(var->getMostRecentDecl());
+ if (const VarDecl *Var = dyn_cast<VarDecl>(this)) {
+ if (llvm::Optional<Visibility> V =
+ getVisibilityOf(Var->getMostRecentDecl()))
+ return V;
+ if (Var->isStaticDataMember()) {
+ VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember();
+ if (InstantiatedFrom)
+ return getVisibilityOf(InstantiatedFrom);
+ }
+
+ return llvm::Optional<Visibility>();
+ }
// Use the most recent declaration of a function, and also handle
// function template specializations.
if (const FunctionDecl *fn = dyn_cast<FunctionDecl>(this)) {
diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp
index 9de9265..be8e199 100644
--- a/test/CodeGenCXX/visibility.cpp
+++ b/test/CodeGenCXX/visibility.cpp
@@ -54,6 +54,18 @@
// CHECK-HIDDEN: @_ZN6test299data_rectE = global
}
+namespace test40 {
+ template<typename T>
+ struct foo {
+ DEFAULT static int bar;
+ };
+ template<typename T>
+ int foo<T>::bar;
+ template struct foo<int>;
+ // CHECK: _ZN6test403fooIiE3barE = weak_odr global
+ // CHECK-HIDDEN: _ZN6test403fooIiE3barE = weak_odr global
+}
+
// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
// CHECK: @_ZN5Test71aE = hidden global
// CHECK: @_ZN5Test71bE = global