mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-02 23:56:05 +00:00
Consider visibility attributes last, so that they take precedence.
I am working on a cleaner fix, but this gets the case in PR12552 passing. llvm-svn: 154749
This commit is contained in:
parent
e298063669
commit
0aec8ece52
@ -281,27 +281,6 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, LVFlags F) {
|
||||
LinkageInfo LV;
|
||||
LV.mergeVisibility(Context.getLangOpts().getVisibilityMode());
|
||||
|
||||
if (F.ConsiderVisibilityAttributes) {
|
||||
if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
|
||||
LV.setVisibility(*Vis, true);
|
||||
F.ConsiderGlobalVisibility = false;
|
||||
} else {
|
||||
// If we're declared in a namespace with a visibility attribute,
|
||||
// use that namespace's visibility, but don't call it explicit.
|
||||
for (const DeclContext *DC = D->getDeclContext();
|
||||
!isa<TranslationUnitDecl>(DC);
|
||||
DC = DC->getParent()) {
|
||||
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
|
||||
if (!ND) continue;
|
||||
if (llvm::Optional<Visibility> Vis = ND->getExplicitVisibility()) {
|
||||
LV.setVisibility(*Vis, true);
|
||||
F.ConsiderGlobalVisibility = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// C++ [basic.link]p4:
|
||||
|
||||
// A name having namespace scope has external linkage if it is the
|
||||
@ -478,6 +457,27 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, LVFlags F) {
|
||||
return LinkageInfo::none();
|
||||
}
|
||||
|
||||
if (F.ConsiderVisibilityAttributes) {
|
||||
if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
|
||||
LV.setVisibility(*Vis, true);
|
||||
F.ConsiderGlobalVisibility = false;
|
||||
} else {
|
||||
// If we're declared in a namespace with a visibility attribute,
|
||||
// use that namespace's visibility, but don't call it explicit.
|
||||
for (const DeclContext *DC = D->getDeclContext();
|
||||
!isa<TranslationUnitDecl>(DC);
|
||||
DC = DC->getParent()) {
|
||||
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
|
||||
if (!ND) continue;
|
||||
if (llvm::Optional<Visibility> Vis = ND->getExplicitVisibility()) {
|
||||
LV.setVisibility(*Vis, true);
|
||||
F.ConsiderGlobalVisibility = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we ended up with non-external linkage, visibility should
|
||||
// always be default.
|
||||
if (LV.linkage() != ExternalLinkage)
|
||||
|
@ -28,6 +28,18 @@ namespace test28 {
|
||||
// CHECK-HIDDEN: @_ZN6test285myvecE = hidden global
|
||||
}
|
||||
|
||||
namespace test29 {
|
||||
#pragma GCC visibility push(hidden)
|
||||
struct RECT {
|
||||
int top;
|
||||
};
|
||||
__attribute__ ((visibility ("default"))) extern RECT data_rect;
|
||||
RECT data_rect = { -1};
|
||||
#pragma GCC visibility pop
|
||||
// CHECK: @_ZN6test299data_rectE = global
|
||||
// CHECK-HIDDEN: @_ZN6test299data_rectE = global
|
||||
}
|
||||
|
||||
// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
|
||||
// CHECK: @_ZN5Test71aE = hidden global
|
||||
// CHECK: @_ZN5Test71bE = global
|
||||
|
Loading…
x
Reference in New Issue
Block a user