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

Anders Carlsson andersca at mac.com
Sat Feb 6 17:44:37 PST 2010


Author: andersca
Date: Sat Feb  6 19:44:36 2010
New Revision: 95511

URL: http://llvm.org/viewvc/llvm-project?rev=95511&view=rev
Log:
Improved handling of the visibility attribute. Declarations now inherit their parent's visibility.

(This is kind of a risky change, but I did a self-host build and everything appears to work fine!)

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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Feb  6 19:44:36 2010
@@ -132,6 +132,10 @@
     }
   }
 
+  // This decl should have the same visibility as its parent.
+  if (const DeclContext *DC = D->getDeclContext()) 
+    return getDeclVisibilityMode(cast<Decl>(DC));
+
   return getLangOptions().getVisibilityMode();
 }
 

Added: cfe/trunk/test/CodeGenCXX/visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/visibility.cpp?rev=95511&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/visibility.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/visibility.cpp Sat Feb  6 19:44:36 2010
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+
+#define HIDDEN __attribute__((visibility("hidden")))
+#define PROTECTED __attribute__((visibility("protected")))
+#define DEFAULT __attribute__((visibility("default")))
+
+// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
+
+namespace Test1 {
+  // CHECK: define hidden void @_ZN5Test11fEv
+  void HIDDEN f() { }
+  
+}
+
+namespace Test2 {
+  struct HIDDEN A {
+    void f();
+  };
+
+  // A::f is a member function of a hidden class.
+  // CHECK: define hidden void @_ZN5Test21A1fEv
+  void A::f() { }
+}
+ 
+namespace Test3 {
+  struct HIDDEN A {
+    struct B {
+      void f();
+    };
+  };
+
+  // B is a nested class where its parent class is hidden.
+  // CHECK: define hidden void @_ZN5Test31A1B1fEv
+  void A::B::f() { }  
+}
+
+namespace Test4 HIDDEN {
+  int VariableInHiddenNamespace = 10;
+
+  // Test4::g is in a hidden namespace.
+  // CHECK: define hidden void @_ZN5Test41gEv
+  void g() { } 
+  
+  struct DEFAULT A {
+    void f();
+  };
+  
+  // A has default visibility.
+  // CHECK: define void @_ZN5Test41A1fEv
+  void A::f() { } 
+}
+
+namespace Test5 {
+
+  namespace NS HIDDEN {
+    // f is in NS which is hidden.
+    // CHECK: define hidden void @_ZN5Test52NS1fEv()
+    void f() { }
+  }
+  
+  namespace NS {
+    // g is in NS, but this NS decl is not hidden.
+    // CHECK: define void @_ZN5Test52NS1gEv
+    void g() { }
+  }
+}





More information about the cfe-commits mailing list