]> granicus.if.org Git - clang/commitdiff
When laying out vtables for virtual bases in construction vtables, we need to check...
authorAnders Carlsson <andersca@mac.com>
Sun, 28 Feb 2010 18:08:38 +0000 (18:08 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 28 Feb 2010 18:08:38 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97402 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4f3cdde2d8ffba8bb799bac320550643ba678896..40a7b2f180ea6d7f46f1803232c2172fd93a2635 100644 (file)
@@ -1799,9 +1799,22 @@ VtableBuilder::DeterminePrimaryVirtualBases(const CXXRecordDecl *RD,
   
   // Check if this base has a primary base.
   if (const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase()) {
-    // Check if it's virtual
-    if (Layout.getPrimaryBaseWasVirtual())
-      PrimaryVirtualBases.insert(PrimaryBase);
+
+    // Check if it's virtual.
+    if (Layout.getPrimaryBaseWasVirtual()) {
+      bool IsPrimaryVirtualBase = true;
+
+      if (isBuildingConstructorVtable()) {
+        // Check if the base is actually a primary base in the class we use for
+        // layout.
+        // FIXME: Is this check enough?
+        if (MostDerivedClassOffset != 0)
+          IsPrimaryVirtualBase = false;
+      }
+        
+      if (IsPrimaryVirtualBase)
+        PrimaryVirtualBases.insert(PrimaryBase);
+    }
   }
 
   // Traverse bases, looking for more primary virtual bases.
index dce7461e042085b35ce3bba646827b4bb9ecb3b1..615ab6f5645befb0e52e49d1bf44af0715987cff 100644 (file)
@@ -926,6 +926,13 @@ namespace Test24 {
 
 // Another construction vtable test.
 
+struct A {
+  virtual void f();
+};
+
+struct B : virtual A { };
+struct C : virtual A { };
+
 // CHECK:      Vtable for 'Test24::D' (10 entries).
 // CHECK-NEXT:    0 | vbase_offset (0)
 // CHECK-NEXT:    1 | vcall_offset (0)
@@ -952,13 +959,13 @@ namespace Test24 {
 // CHECK-NEXT:        -- (Test24::B, 0) vtable address --
 // CHECK-NEXT:    4 | void Test24::A::f()
 
-struct A {
-  virtual void f();
-};
-
-struct B : virtual A { };
-struct C : virtual A { };
-
+// CHECK:      Construction vtable for ('Test24::C', 8) in 'Test24::D' (9 entries).
+// CHECK-NEXT:    0 | vbase_offset (-8)
+// CHECK-NEXT:    1 | vcall_offset (-8)
+// CHECK-NEXT:    2 | offset_to_top (0)
+// CHECK-NEXT:    3 | Test24::C RTTI
+// CHECK-NEXT:        -- (Test24::A, 8) vtable address --
+// CHECK-NEXT:        -- (Test24::C, 8) vtable address --
 struct D : B, C {
   virtual void f();
 };