Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 119f19b

Browse files
author
Fariborz Jahanian
committed
Set the visibility to 'hidden' when previous
declaration of global var is __private_extern__. // rdar://9609649 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133157 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c370398 commit 119f19b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/CodeGen/CodeGenModule.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,17 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
206206

207207
// Set visibility for definitions.
208208
NamedDecl::LinkageInfo LV = D->getLinkageAndVisibility();
209-
if (LV.visibilityExplicit() || !GV->hasAvailableExternallyLinkage())
210-
GV->setVisibility(GetLLVMVisibility(LV.visibility()));
209+
if (LV.visibilityExplicit() || !GV->hasAvailableExternallyLinkage()) {
210+
Visibility Vis = LV.visibility();
211+
if (Vis == DefaultVisibility)
212+
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
213+
if (const VarDecl *Old = VD->getPreviousDeclaration()) {
214+
Visibility OldVis = Old->getLinkageAndVisibility().visibility();
215+
if (OldVis == HiddenVisibility)
216+
Vis = HiddenVisibility;
217+
}
218+
GV->setVisibility(GetLLVMVisibility(Vis));
219+
}
211220
}
212221

213222
/// Set the symbol visibility of type information (vtable and RTTI)

test/CodeGen/private-extern-redef.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %clang_cc1 -triple x86_64-darwin-apple -emit-llvm -o - %s | FileCheck %s
2+
// rdar://9609649
3+
4+
__private_extern__ const int I;
5+
__private_extern__ const int J = 927;
6+
7+
__private_extern__ const int K;
8+
const int K = 37;
9+
10+
const int L = 10;
11+
__private_extern__ const int L;
12+
13+
__private_extern__ int M;
14+
int M = 20;
15+
16+
__private_extern__ int N;
17+
int N;
18+
19+
__private_extern__ int O;
20+
int O=1;
21+
22+
__private_extern__ int P;
23+
extern int P;
24+
25+
void bar(int);
26+
27+
void foo() {
28+
bar(I);
29+
}
30+
31+
// CHECK: @J = hidden constant
32+
// CHECK: @K = hidden constant
33+
// CHECK: @L = constant
34+
// CHECK: @M = hidden global
35+
// CHECK: @O = hidden global
36+
// CHECK: @I = external hidden
37+
// CHECK: @N = common hidden global
38+
// CHECK-NOT: @P
39+

0 commit comments

Comments
 (0)