[cfe-commits] r97402 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp
Anders Carlsson
andersca at mac.com
Sun Feb 28 10:08:38 PST 2010
Author: andersca
Date: Sun Feb 28 12:08:38 2010
New Revision: 97402
URL: http://llvm.org/viewvc/llvm-project?rev=97402&view=rev
Log:
When laying out vtables for virtual bases in construction vtables, we need to check if the vtable is a primary base in the layout class.
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=97402&r1=97401&r2=97402&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sun Feb 28 12:08:38 2010
@@ -1799,9 +1799,22 @@
// 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.
Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=97402&r1=97401&r2=97402&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Sun Feb 28 12:08:38 2010
@@ -926,6 +926,13 @@
// 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 @@
// 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();
};
More information about the cfe-commits
mailing list