diff options
-rw-r--r-- | lib/AST/Decl.cpp | 14 | ||||
-rw-r--r-- | test/CodeGenCXX/visibility.cpp | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 21405d223d..d31cf0f010 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -633,9 +633,19 @@ LinkageInfo NamedDecl::getLinkageAndVisibility() const { 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 9de9265db2..be8e199532 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -54,6 +54,18 @@ namespace test29 { // 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 |