Internal variables could mistakenly have "hidden" visibility when

their emission was deferred.
 - <rdar://problem/6775234> variables with internal linkage should not
   be exposed with -fvisibility=hidden.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68818 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-04-10 20:26:50 +00:00
Родитель c7a4ba51b8
Коммит 7e714cd931
2 изменённых файлов: 25 добавлений и 10 удалений

Просмотреть файл

@ -99,9 +99,11 @@ void CodeGenModule::ErrorUnsupported(const Decl *D, const char *Type,
/// GlobalValue according to the given clang AST visibility value.
static void setGlobalVisibility(llvm::GlobalValue *GV,
VisibilityAttr::VisibilityTypes Vis) {
// Do not change the visibility of internal definitions.
if (GV->hasInternalLinkage())
// Internal definitions should always have default visibility.
if (GV->hasInternalLinkage()) {
GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
return;
}
switch (Vis) {
default: assert(0 && "Unknown visibility!");
@ -119,9 +121,11 @@ static void setGlobalVisibility(llvm::GlobalValue *GV,
static void setGlobalOptionVisibility(llvm::GlobalValue *GV,
LangOptions::VisibilityMode Vis) {
// Do not change the visibility of internal definitions.
if (GV->hasInternalLinkage())
// Internal definitions should always have default visibility.
if (GV->hasInternalLinkage()) {
GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
return;
}
switch (Vis) {
default: assert(0 && "Unknown visibility!");
@ -780,11 +784,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
GV->setConstant(D->getType().isConstant(Context));
GV->setAlignment(getContext().getDeclAlignInBytes(D));
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
setGlobalVisibility(GV, attr->getVisibility());
else
setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode());
// Set the llvm linkage type as appropriate.
if (D->getStorageClass() == VarDecl::Static)
GV->setLinkage(llvm::Function::InternalLinkage);
@ -819,6 +818,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
}
}
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
setGlobalVisibility(GV, attr->getVisibility());
else
setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode());
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());

Просмотреть файл

@ -2,29 +2,40 @@
// RUN: grep '@g_com = common global i32 0' %t &&
// RUN: grep '@g_def = global i32 0' %t &&
// RUN: grep '@g_ext = external global i32' %t &&
// RUN: grep '@g_deferred = internal global' %t &&
// RUN: grep 'declare void @f_ext()' %t &&
// RUN: grep 'define internal void @f_deferred()' %t &&
// RUN: grep 'define i32 @f_def()' %t &&
// RUN: clang-cc -triple i386-unknown-unknown -fvisibility=protected -emit-llvm -o %t %s &&
// RUN: grep '@g_com = common protected global i32 0' %t &&
// RUN: grep '@g_def = protected global i32 0' %t &&
// RUN: grep '@g_ext = external global i32' %t &&
// RUN: grep '@g_deferred = internal global' %t &&
// RUN: grep 'declare void @f_ext()' %t &&
// RUN: grep 'define internal void @f_deferred()' %t &&
// RUN: grep 'define protected i32 @f_def()' %t &&
// RUN: clang-cc -triple i386-unknown-unknown -fvisibility=hidden -emit-llvm -o %t %s &&
// RUN: grep '@g_com = common hidden global i32 0' %t &&a
// RUN: grep '@g_def = hidden global i32 0' %t &&
// RUN: grep '@g_ext = external global i32' %t &&
// RUN: grep '@g_deferred = internal global' %t &&
// RUN: grep 'declare void @f_ext()' %t &&
// RUN: grep 'define internal void @f_deferred()' %t &&
// RUN: grep 'define hidden i32 @f_def()' %t &&
// RUN: true
int g_com;
int g_def = 0;
extern int g_ext;
static char g_deferred[] = "hello";
extern void f_ext(void);
static void f_deferred(void) {
}
int f_def(void) {
f_ext();
return g_com + g_def + g_ext;
f_deferred();
return g_com + g_def + g_ext + g_deferred[0];
}