[cfe-commits] r90680 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/virt-template-vtable.cpp test/CodeGenCXX/vtable-linkage.cpp

Anders Carlsson andersca at mac.com
Sat Dec 5 14:24:39 PST 2009


Author: andersca
Date: Sat Dec  5 16:24:38 2009
New Revision: 90680

URL: http://llvm.org/viewvc/llvm-project?rev=90680&view=rev
Log:
If a class does not have a key function, its linkage should be weak_odr.

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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sat Dec  5 16:24:38 2009
@@ -1092,7 +1092,7 @@
   
   // Figure out the right linkage.
   llvm::GlobalVariable::LinkageTypes Linkage = 
-    llvm::GlobalValue::LinkOnceODRLinkage;
+    llvm::GlobalValue::WeakODRLinkage;
   if (!Init)
     Linkage = llvm::GlobalValue::ExternalLinkage;
   else if (RD->isInAnonymousNamespace())
@@ -1167,7 +1167,7 @@
                                       b.getVtable().size());
     }
     llvm::GlobalVariable *OGV = GV;
-    GV = createGlobalVariable(*this, LayoutClass, ntype, C, Name);
+    GV = createGlobalVariable(*this, LayoutClass, ArrayType, Init, Name);
     if (OGV) {
       GV->takeName(OGV);
       llvm::Constant *NewPtr = 

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=90680&r1=90679&r2=90680&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp Sat Dec  5 16:24:38 2009
@@ -9,4 +9,4 @@
 };
 B::B() {}
 
-// CHECK: @_ZTV1AIiE = linkonce_odr constant
+// CHECK: @_ZTV1AIiE = weak_odr constant

Modified: cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp?rev=90680&r1=90679&r2=90680&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp Sat Dec  5 16:24:38 2009
@@ -15,10 +15,20 @@
 
 B::B() { }
 
+struct C {
+  C();
+  virtual void f() { } 
+};
+
+C::C() { } 
+
 // B has a key function that is not defined in this translation unit so its vtable
 // has external linkage.
 // CHECK: @_ZTV1B = external constant
 
+// C has no key function, so its vtable should have weak_odr linkage.
+// CHECK: @_ZTV1C = weak_odr constant
+
 // The A vtable should have internal linkage since it is inside an anonymous 
 // namespace.
 // CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant





More information about the cfe-commits mailing list