]> granicus.if.org Git - clang/commitdiff
Ignore non-interesting bases when emitting construction vtables.
authorAnders Carlsson <andersca@mac.com>
Wed, 10 Mar 2010 19:15:26 +0000 (19:15 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 10 Mar 2010 19:15:26 +0000 (19:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98177 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVtable.cpp
test/CodeGenCXX/vtable-layout.cpp

index 4500ec033cd8bcdf08d8e3250c9c00371277b2dc..caf1e1f93e4823c7c702d37fe28cb629c3775fcc 100644 (file)
@@ -1800,6 +1800,17 @@ void VtableBuilder::LayoutSecondaryVtables(BaseSubobject Base,
     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;
index 5c783f1f23dc4bce8c29e46d15b4ec3ba71e3a63..19619d0f2b8e4ce3965af264bad87ac139433d93 100644 (file)
@@ -1091,3 +1091,63 @@ class D : virtual B, virtual C {
 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() { }
+}