[cfe-commits] r117532 - in /cfe/trunk: lib/AST/Decl.cpp test/CodeGenCXX/visibility.cpp

John McCall rjmccall at apple.com
Thu Oct 28 00:07:52 PDT 2010


Author: rjmccall
Date: Thu Oct 28 02:07:52 2010
New Revision: 117532

URL: http://llvm.org/viewvc/llvm-project?rev=117532&view=rev
Log:
Abandon the type-visibility optimization for functions.  GCC doesn't do it,
and it's too much trouble to push for.  Fixes PR8478.


Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/CodeGenCXX/visibility.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=117532&r1=117531&r2=117532&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Oct 28 02:07:52 2010
@@ -268,15 +268,10 @@
 
   //     - a function, unless it has internal linkage; or
   } else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
-    // Modify the function's LV by the LV of its type unless this is
-    // C or extern "C".  See the comment above about variables.
-    if (Context.getLangOptions().CPlusPlus && !Function->isExternC() &&
-        !ExplicitVisibility) {
-      LVPair TypeLV = Function->getType()->getLinkageAndVisibility();
-      if (TypeLV.first != ExternalLinkage)
-        return LVPair(UniqueExternalLinkage, DefaultVisibility);
-      LV.second = minVisibility(LV.second, TypeLV.second);
-    }
+    // In theory, we can modify the function's LV by the LV of its
+    // type unless it has C linkage (see comment above about variables
+    // for justification).  In practice, GCC doesn't do this, so it's
+    // just too painful to make work.
 
     // C99 6.2.2p5:
     //   If the declaration of an identifier for a function has no
@@ -437,11 +432,11 @@
   const VisibilityAttr *VA = GetExplicitVisibility(D);
   if (VA) LV.second = minVisibility(LV.second, GetVisibilityFromAttr(VA));
 
-  // If it's a value declaration and we don't have an explicit visibility
-  // attribute, apply the LV from its type.
+  // If it's a variable declaration and we don't have an explicit
+  // visibility attribute, apply the LV from its type.
   // See the comment about namespace-scope variable decls above.
-  if (!VA && isa<ValueDecl>(D)) {
-    LVPair TypeLV = cast<ValueDecl>(D)->getType()->getLinkageAndVisibility();
+  if (!VA && isa<VarDecl>(D)) {
+    LVPair TypeLV = cast<VarDecl>(D)->getType()->getLinkageAndVisibility();
     if (TypeLV.first != ExternalLinkage)
       LV.first = minLinkage(LV.first, UniqueExternalLinkage);
     LV.second = minVisibility(LV.second, TypeLV.second);

Modified: cfe/trunk/test/CodeGenCXX/visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/visibility.cpp?rev=117532&r1=117531&r2=117532&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/visibility.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/visibility.cpp Thu Oct 28 02:07:52 2010
@@ -133,3 +133,16 @@
     test9_fun(&a);
   }
 }
+
+// PR8478
+namespace Test10 {
+  struct A;
+
+  DEFAULT class B {
+    void foo(A*);
+  };
+
+  // CHECK: define void @_ZN6Test101B3fooEPNS_1AE(
+  // CHECK-HIDDEN: define void @_ZN6Test101B3fooEPNS_1AE(
+  void B::foo(A*) {}
+}





More information about the cfe-commits mailing list