[cfe-commits] r68818 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/visibility.c

Daniel Dunbar daniel at zuster.org
Fri Apr 10 13:26:50 PDT 2009


Author: ddunbar
Date: Fri Apr 10 15:26:50 2009
New Revision: 68818

URL: http://llvm.org/viewvc/llvm-project?rev=68818&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/visibility.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68818&r1=68817&r2=68818&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr 10 15:26:50 2009
@@ -99,9 +99,11 @@
 /// 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 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 @@
   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 @@
     }
   }
 
+  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());
 

Modified: cfe/trunk/test/CodeGen/visibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/visibility.c?rev=68818&r1=68817&r2=68818&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/visibility.c (original)
+++ cfe/trunk/test/CodeGen/visibility.c Fri Apr 10 15:26:50 2009
@@ -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];
 }





More information about the cfe-commits mailing list