When recording empty subobjects we should always look at the primary virtual base.

llvm-svn: 104464
This commit is contained in:
Anders Carlsson 2010-05-23 18:14:24 +00:00
parent 3ff1a06de6
commit 5773205a8d
2 changed files with 25 additions and 0 deletions

View File

@ -530,8 +530,15 @@ void ASTRecordLayoutBuilder::UpdateEmptyClassOffsets(const CXXRecordDecl *RD,
UpdateEmptyClassOffsets(FD, Offset + FieldOffset);
}
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
if (UpdateVBases) {
// FIXME: Update virtual bases.
} else if (PrimaryBase && Layout.getPrimaryBaseWasVirtual()) {
// We always want to update the offsets of a primary virtual base.
assert(Layout.getVBaseClassOffset(PrimaryBase) == 0 &&
"primary base class offset must always be 0!");
UpdateEmptyClassOffsets(PrimaryBase, Offset, /*UpdateVBases=*/false);
}
}

View File

@ -2,6 +2,8 @@
#define SA(n, p) int a##n[(p) ? 1 : -1]
namespace Test0 {
struct A { int a; };
SA(0, sizeof(A) == 4);
@ -66,3 +68,19 @@ SA(11, sizeof(S7) == 8);
struct S8 : Empty, A {
};
SA(12, sizeof(S8) == 4);
}
namespace Test1 {
// Test that we don't try to place both A subobjects at offset 0.
struct A { };
class B { virtual void f(); };
class C : A, virtual B { };
struct D : virtual C { };
struct E : virtual A { };
class F : D, E { };
SA(0, sizeof(F) == 24);
}