[ms-abi] Leading VFPtrs don't suppress the leading zero sized flag

The MS-ABI tracks a bit that asserts that the first sub-object is zero 
sized.  This bit is used to add padding between objects if there's the 
potential for zero sized objects to alias.  The bit is still true even 
if the zero sized base is lead by a VFPtr.  This patch makes clang mimic 
that behavior.

llvm-svn: 199132
This commit is contained in:
Warren Hunt 2014-01-13 19:55:52 +00:00
parent 50501fbe38
commit badf9e0f84
2 changed files with 47 additions and 1 deletions

View File

@ -2302,8 +2302,10 @@ MicrosoftRecordLayoutBuilder::layoutNonVirtualBases(const CXXRecordDecl *RD) {
if (!BaseLayout.hasExtendableVFPtr())
continue;
// If we don't have a primary base, this one qualifies.
if (!PrimaryBase)
if (!PrimaryBase) {
PrimaryBase = BaseDecl;
LeadsWithZeroSizedBase = BaseLayout.leadsWithZeroSizedBase();
}
// Lay out the base.
layoutNonVirtualBase(BaseDecl, BaseLayout, PreviousBaseLayout);
}

View File

@ -255,10 +255,54 @@ struct F : virtual D, virtual B {};
// CHECK-X64-NEXT: | [sizeof=32, align=8
// CHECK-X64-NEXT: | nvsize=8, nvalign=8]
struct JC0 {
JC0() { printf("JC0 : %d\n", (int)((char*)this - buffer)); }
};
struct JC1 : JC0 {
virtual void f() {}
JC1() { printf("JC1 : %d\n", (int)((char*)this - buffer)); }
};
struct JC2 : JC1 {
JC2() { printf("JC2 : %d\n", (int)((char*)this - buffer)); }
};
struct JC4 : JC1, JC2 {
JC4() { printf("JC4 : %d\n", (int)((char*)this - buffer)); }
};
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct JC4
// CHECK-NEXT: 0 | struct JC1 (primary base)
// CHECK-NEXT: 0 | (JC1 vftable pointer)
// CHECK-NEXT: 4 | struct JC0 (base) (empty)
// CHECK-NEXT: 8 | struct JC2 (base)
// CHECK-NEXT: 8 | struct JC1 (primary base)
// CHECK-NEXT: 8 | (JC1 vftable pointer)
// CHECK-NEXT: 12 | struct JC0 (base) (empty)
// CHECK-NEXT: | [sizeof=12, align=4
// CHECK-NEXT: | nvsize=12, nvalign=4]
// CHECK-x64: *** Dumping AST Record Layout
// CHECK-x64: *** Dumping AST Record Layout
// CHECK-x64: *** Dumping AST Record Layout
// CHECK-x64: *** Dumping AST Record Layout
// CHECK-x64-NEXT: 0 | struct JC4
// CHECK-x64-NEXT: 0 | struct JC1 (primary base)
// CHECK-x64-NEXT: 0 | (JC1 vftable pointer)
// CHECK-x64-NEXT: 8 | struct JC0 (base) (empty)
// CHECK-x64-NEXT: 16 | struct JC2 (base)
// CHECK-x64-NEXT: 16 | struct JC1 (primary base)
// CHECK-x64-NEXT: 16 | (JC1 vftable pointer)
// CHECK-x64-NEXT: 24 | struct JC0 (base) (empty)
// CHECK-x64-NEXT: | [sizeof=24, align=8
// CHECK-x64-NEXT: | nvsize=24, nvalign=8]
int a[
sizeof(AT3) +
sizeof(BT3) +
sizeof(T3) +
sizeof(E) +
sizeof(F) +
sizeof(JC4) +
0];