/// 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!");
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!");
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);
}
}
+ 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());
// 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];
}