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.
llvm-svn: 97402
diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp
index 4f3cdde..40a7b2f 100644
--- a/clang/lib/CodeGen/CGVtable.cpp
+++ b/clang/lib/CodeGen/CGVtable.cpp
@@ -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.