From: Daniel Dunbar Date: Tue, 7 Apr 2009 22:36:33 +0000 (+0000) Subject: Visibility attributes should only be set on definition. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03abc9ec05e8edce5e8d0c7f08a05027b9e04170;p=clang Visibility attributes should only be set on definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68561 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 1dd2c4d67f..508d7ce2b6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -272,10 +272,12 @@ void CodeGenModule::SetGlobalValueAttributes(const Decl *D, // FIXME: Figure out the relative priority of the attribute, // -fvisibility, and private_extern. - if (const VisibilityAttr *attr = D->getAttr()) - setGlobalVisibility(GV, attr->getVisibility()); - else - setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode()); + if (ForDefinition) { + if (const VisibilityAttr *attr = D->getAttr()) + setGlobalVisibility(GV, attr->getVisibility()); + else + setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode()); + } if (const SectionAttr *SA = D->getAttr()) GV->setSection(SA->getName()); diff --git a/test/CodeGen/visibility-option.c b/test/CodeGen/visibility-option.c deleted file mode 100644 index 41b77cab1d..0000000000 --- a/test/CodeGen/visibility-option.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: clang-cc -fvisibility=hidden -emit-llvm -o - %s | grep -e "hidden" | count 2 - -int Global = 10; - -void Func() {} - diff --git a/test/CodeGen/visibility.c b/test/CodeGen/visibility.c new file mode 100644 index 0000000000..42d66f9b83 --- /dev/null +++ b/test/CodeGen/visibility.c @@ -0,0 +1,30 @@ +// RUN: clang-cc -triple i386-unknown-unknown -fvisibility=default -emit-llvm -o %t %s && +// 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 'declare void @f_ext()' %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 'declare void @f_ext()' %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 'declare void @f_ext()' %t && +// RUN: grep 'define hidden i32 @f_def()' %t && +// RUN: true + +int g_com; +int g_def = 0; +extern int g_ext; + +extern void f_ext(void); + +int f_def(void) { + f_ext(); + return g_com + g_def + g_ext; +}