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

Anders Carlsson andersca at mac.com
Wed Mar 10 11:15:26 PST 2010


Author: andersca
Date: Wed Mar 10 13:15:26 2010
New Revision: 98177

URL: http://llvm.org/viewvc/llvm-project?rev=98177&view=rev
Log:
Ignore non-interesting bases when emitting construction vtables.

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=98177&r1=98176&r2=98177&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Wed Mar 10 13:15:26 2010
@@ -1800,6 +1800,17 @@
     if (!BaseDecl->isDynamicClass())
       continue;
 
+    if (isBuildingConstructorVtable()) {
+      // Itanium C++ ABI 2.6.4:
+      //   Some of the base class subobjects may not need construction virtual
+      //   tables, which will therefore not be present in the construction
+      //   virtual table group, even though the subobject virtual tables are
+      //   present in the main virtual table group for the complete object.
+      if (!BaseDecl->getNumVBases()) {
+        continue;
+      }
+    }
+
     // Get the base offset of this base.
     uint64_t RelativeBaseOffset = Layout.getBaseClassOffset(BaseDecl);
     uint64_t BaseOffset = Base.getBaseOffset() + RelativeBaseOffset;

Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=98177&r1=98176&r2=98177&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Wed Mar 10 13:15:26 2010
@@ -1091,3 +1091,63 @@
 void D::d() { } 
 
 }
+
+namespace Test27 {
+
+// Test that we don't generate a secondary vtable for C in the D-in-E vtable, since
+// C doesn't have any virtual bases.
+
+struct A {
+  virtual void a();
+};
+
+struct B {
+  virtual void b();
+};
+
+struct C {
+  virtual void c();
+};
+
+struct D : A, virtual B, C {
+  virtual void d();
+};
+
+// CHECK:      Vtable for 'Test27::E' (13 entries).
+// CHECK-NEXT:    0 | vbase_offset (16)
+// CHECK-NEXT:    1 | offset_to_top (0)
+// CHECK-NEXT:    2 | Test27::E RTTI
+// CHECK-NEXT:        -- (Test27::A, 0) vtable address --
+// CHECK-NEXT:        -- (Test27::D, 0) vtable address --
+// CHECK-NEXT:        -- (Test27::E, 0) vtable address --
+// CHECK-NEXT:    3 | void Test27::A::a()
+// CHECK-NEXT:    4 | void Test27::D::d()
+// CHECK-NEXT:    5 | void Test27::E::e()
+// CHECK-NEXT:    6 | offset_to_top (-8)
+// CHECK-NEXT:    7 | Test27::E RTTI
+// CHECK-NEXT:        -- (Test27::C, 8) vtable address --
+// CHECK-NEXT:    8 | void Test27::C::c()
+// CHECK-NEXT:    9 | vcall_offset (0)
+// CHECK-NEXT:   10 | offset_to_top (-16)
+// CHECK-NEXT:   11 | Test27::E RTTI
+// CHECK-NEXT:        -- (Test27::B, 16) vtable address --
+// CHECK-NEXT:   12 | void Test27::B::b()
+
+// CHECK:      Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries).
+// CHECK-NEXT:    0 | vbase_offset (16)
+// CHECK-NEXT:    1 | offset_to_top (0)
+// CHECK-NEXT:    2 | Test27::D RTTI
+// CHECK-NEXT:        -- (Test27::A, 0) vtable address --
+// CHECK-NEXT:        -- (Test27::D, 0) vtable address --
+// CHECK-NEXT:    3 | void Test27::A::a()
+// CHECK-NEXT:    4 | void Test27::D::d()
+// CHECK-NEXT:    5 | vcall_offset (0)
+// CHECK-NEXT:    6 | offset_to_top (-16)
+// CHECK-NEXT:    7 | Test27::D RTTI
+// CHECK-NEXT:        -- (Test27::B, 16) vtable address --
+// CHECK-NEXT:    8 | void Test27::B::b()
+struct E : D {
+  virtual void e();
+};
+void E::e() { }
+}





More information about the cfe-commits mailing list