[cfe-commits] r90751 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-key-function.cpp

Anders Carlsson andersca at mac.com
Sun Dec 6 23:59:53 PST 2009


Author: andersca
Date: Mon Dec  7 01:59:52 2009
New Revision: 90751

URL: http://llvm.org/viewvc/llvm-project?rev=90751&view=rev
Log:
It's OK to try to emit a vtable definition more than once. Fixes PR5697.

Added:
    cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Mon Dec  7 01:59:52 2009
@@ -1400,8 +1400,13 @@
 
 void CGVtableInfo::GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage,
                                      const CXXRecordDecl *RD) {
-  assert(!Vtables.count(RD) && "Vtable has already been generated!");
-  Vtables[RD] = GenerateVtable(Linkage, /*GenerateDefinition=*/true, RD, RD, 0);
+  llvm::GlobalVariable *&Vtable = Vtables[RD];
+  if (Vtable) {
+    assert(Vtable->getInitializer() && "Vtable doesn't have a definition!");
+    return;
+  }
+  
+  Vtable = GenerateVtable(Linkage, /*GenerateDefinition=*/true, RD, RD, 0);
   
   CGM.GenerateRTTI(RD);
   GenerateVTT(Linkage, RD);  

Added: cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp?rev=90751&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/vtable-key-function.cpp Mon Dec  7 01:59:52 2009
@@ -0,0 +1,15 @@
+// RUN: clang-cc %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// PR5697
+namespace PR5697 {
+struct A {
+  virtual void f() { } 
+  A();
+  A(int);
+};
+
+// 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
+A::A() { }
+A::A(int) { }
+}





More information about the cfe-commits mailing list