diff options
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGen/visibility-option.c | 6 | ||||
-rw-r--r-- | clang/test/CodeGen/visibility.c | 30 |
3 files changed, 36 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1dd2c4d67f0..508d7ce2b6f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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<VisibilityAttr>()) - setGlobalVisibility(GV, attr->getVisibility()); - else - setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode()); + if (ForDefinition) { + 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()); diff --git a/clang/test/CodeGen/visibility-option.c b/clang/test/CodeGen/visibility-option.c deleted file mode 100644 index 41b77cab1df..00000000000 --- a/clang/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/clang/test/CodeGen/visibility.c b/clang/test/CodeGen/visibility.c new file mode 100644 index 00000000000..42d66f9b832 --- /dev/null +++ b/clang/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; +} |