[AST] correct the behavior of -fvisibility-inlines-hidden option (don't make static local variables hidden)
The command line option -fvisibility-inlines-hidden makes inlined method hidden, but it is expected not to affect the visibility of static local variables in the function.
However, Clang makes the static local variables in the function also hidden as reported in PR37595. This problem causes LLVM bootstarp failure on Fedora 28 if configured with -DBUILD_SHARED_LIBS=ON.
This patch makes the behavior of -fvisibility-inlines-hidden option to be consistent with that of gcc; the option does not change the visibility of the static local variables if the containing function does not associated with explicit visibility attribute and becomes hidden due to this option.
Differential Revision: https://reviews.llvm.org/D50968
llvm-svn: 340386
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index b6d35f4..272e49a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1262,6 +1262,16 @@
!isTemplateInstantiation(FD->getTemplateSpecializationKind()))
return LinkageInfo::none();
+ // If a function is hidden by -fvisibility-inlines-hidden option and
+ // is not explicitly attributed as a hidden function,
+ // we should not make static local variables in the function hidden.
+ if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
+ !(!hasExplicitVisibilityAlready(computation) &&
+ getExplicitVisibility(FD, computation))) {
+ assert(cast<VarDecl>(D)->isStaticLocal());
+ return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false);
+ }
+
LV = getLVForDecl(FD, computation);
}
if (!isExternallyVisible(LV.getLinkage()))