[cfe-commits] r110107 - in /cfe/trunk: lib/CodeGen/CGVTables.cpp test/CodeGenCXX/key-function-vtable.cpp test/CodeGenCXX/virt-template-vtable.cpp test/CodeGenCXX/vtable-key-function.cpp test/CodeGenCXX/vtable-linkage.cpp

John McCall rjmccall at apple.com
Tue Aug 3 00:24:12 PDT 2010


Author: rjmccall
Date: Tue Aug  3 02:24:12 2010
New Revision: 110107

URL: http://llvm.org/viewvc/llvm-project?rev=110107&view=rev
Log:
Emit weak vtables of non-template classes with hidden visibility.


Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp
    cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
    cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp
    cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=110107&r1=110106&r2=110107&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Aug  3 02:24:12 2010
@@ -2926,6 +2926,22 @@
   
   // Set the right visibility.
   CGM.setGlobalVisibility(VTable, RD);
+
+  // It's okay to have multiple copies of a vtable, so don't make the
+  // dynamic linker unique them.  Suppress this optimization if it's
+  // possible that there might be unresolved references elsewhere,
+  // which can happen if
+  //   - there's a key function and the vtable is getting emitted weak
+  //     anyway for whatever reason
+  //   - there might be an explicit instantiation declaration somewhere,
+  //     i.e. if it's a template at all
+  if (Linkage == llvm::GlobalVariable::WeakODRLinkage &&
+      VTable->getVisibility() == llvm::GlobalVariable::DefaultVisibility &&
+      !RD->hasAttr<VisibilityAttr>() &&
+      RD->getTemplateSpecializationKind() == TSK_Undeclared &&
+      !CGM.Context.getKeyFunction(RD)) {
+    VTable->setVisibility(llvm::GlobalVariable::HiddenVisibility);
+  }
 }
 
 llvm::GlobalVariable *

Modified: cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp?rev=110107&r1=110106&r2=110107&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp Tue Aug  3 02:24:12 2010
@@ -12,11 +12,11 @@
 struct testc { virtual void a(); };
 inline void testc::a() {}
 
-// Key functions with inline specifier (PR5705)
+// Functions with inline specifier are not key functions (PR5705)
 struct testd { inline virtual void a(); };
 void testd::a() {}
 
-// Key functions with inline specifier (PR5705)
+// Functions with inline specifier are not key functions (PR5705)
 struct teste { inline virtual void a(); };
 teste *testevar = new teste;
 
@@ -47,5 +47,5 @@
 // CHECK: @_ZTV5testa = constant [3 x i8*] [i8* null
 // CHECK: @_ZTV5testc = weak_odr constant [3 x i8*] [i8* null
 // CHECK: @_ZTVN12_GLOBAL__N_15testgE = internal constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5teste = weak_odr constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5testb = weak_odr constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5teste = weak_odr hidden constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5testb = weak_odr hidden constant [3 x i8*] [i8* null

Modified: cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp?rev=110107&r1=110106&r2=110107&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp Tue Aug  3 02:24:12 2010
@@ -10,4 +10,13 @@
 };
 B::B() {}
 
+template class A<long>;
+
+extern template class A<short>;
+template class A<short>;
+
+
+// CHECK: @_ZTV1B = weak_odr hidden constant
+// CHECK: @_ZTV1AIlE = weak_odr constant
+// CHECK: @_ZTV1AIsE = weak_odr constant
 // CHECK: @_ZTV1AIiE = weak_odr constant

Modified: cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp?rev=110107&r1=110106&r2=110107&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp Tue Aug  3 02:24:12 2010
@@ -9,7 +9,7 @@
 
 // A does not have a key function, so the first constructor we emit should
 // cause the vtable to be defined (without assertions.)
-// CHECK: @_ZTVN6PR56971AE = weak_odr constant
+// CHECK: @_ZTVN6PR56971AE = weak_odr hidden constant
 A::A() { }
 A::A(int) { }
 }

Modified: cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp?rev=110107&r1=110106&r2=110107&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp Tue Aug  3 02:24:12 2010
@@ -95,8 +95,9 @@
 // has external linkage.
 // CHECK-1: @_ZTV1B = external constant
 
-// C has no key function, so its vtable should have weak_odr linkage.
-// CHECK-2: @_ZTV1C = weak_odr constant
+// C has no key function, so its vtable should have weak_odr linkage
+// and hidden visibility (rdar://problem/7523229).
+// CHECK-2: @_ZTV1C = weak_odr hidden constant
 // CHECK-2: @_ZTS1C = weak_odr constant
 // CHECK-2: @_ZTI1C = weak_odr constant
 





More information about the cfe-commits mailing list