[cfe-commits] r96171 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp

Anders Carlsson andersca at mac.com
Sun Feb 14 09:05:59 PST 2010


Author: andersca
Date: Sun Feb 14 11:05:59 2010
New Revision: 96171

URL: http://llvm.org/viewvc/llvm-project?rev=96171&view=rev
Log:
Don't compute final overriders or build vtables for bases that don't need a vtable.

Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/test/CodeGenCXX/vtable-layout.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sun Feb 14 11:05:59 2010
@@ -498,6 +498,10 @@
     const CXXRecordDecl *BaseDecl = 
       cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
     
+    // Ignore bases that don't have any virtual member functions.
+    if (!BaseDecl->isPolymorphic())
+      continue;
+    
     uint64_t BaseOffset;
     if (I->isVirtual()) {
       BaseOffset = MostDerivedClassLayout.getVBaseClassOffset(BaseDecl);
@@ -528,6 +532,10 @@
     const CXXRecordDecl *BaseDecl = 
       cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
     
+    // Ignore bases that don't have any virtual member functions.
+    if (!BaseDecl->isPolymorphic())
+      continue;
+
     uint64_t BaseOffset;
     if (I->isVirtual()) {
       if (!VisitedVirtualBases.insert(BaseDecl)) {
@@ -949,7 +957,9 @@
 
 void VtableBuilder::layoutVtable(BaseSubobject Base) {
   const CXXRecordDecl *RD = Base.getBase();
-  
+
+  assert(RD->isDynamicClass() && "class does not have a vtable!");
+
   // First, add the offset to top.
   // FIXME: This is not going to be right for construction vtables.
   // FIXME: We should not use / 8 here.
@@ -987,11 +997,15 @@
        E = RD->bases_end(); I != E; ++I) {
     const CXXRecordDecl *BaseDecl = 
       cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
-    
+
     // Ignore the primary base.
     if (BaseDecl == PrimaryBase)
       continue;
-    
+
+    // Ignore bases that don't have a vtable.
+    if (!BaseDecl->isDynamicClass())
+      continue;
+
     assert(!I->isVirtual() && "FIXME: Handle virtual bases");
     
     // Get the base offset of this base.

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Sun Feb 14 11:05:59 2010
@@ -321,3 +321,22 @@
 void D::f() { }
 
 }
+
+namespace Test8 {
+
+// Test that we don't try to layout vtables for classes that don't have
+// virtual bases or virtual member functions.
+
+struct A { };
+
+// CHECK:     Vtable for 'Test8::B' (3 entries).
+// CHECK-NEXT:   0 | offset_to_top (0)
+// CHECK-NEXT:   1 | Test8::B RTTI
+// CHECK-NEXT:       -- (Test8::B, 0) vtable address --
+// CHECK-NEXT:   2 | void Test8::B::f()
+struct B : A { 
+  virtual void f();
+};
+void B::f() { }
+
+}





More information about the cfe-commits mailing list