forked from OSchip/llvm-project
[ms-abi] Update Alignment for VtorDisps
The alignment impact of the virtual bases apperas to be applied in order, rather than up front. This patch adds the new behavior and provides a test case. llvm-svn: 197639
This commit is contained in:
parent
47f3c64a48
commit
f037bd1e7c
|
@ -2525,14 +2525,6 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
|
|||
if (!HasVBPtr)
|
||||
return;
|
||||
|
||||
// Update the alignment
|
||||
for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
|
||||
e = RD->vbases_end();
|
||||
i != e; ++i) {
|
||||
const CXXRecordDecl *BaseDecl = i->getType()->getAsCXXRecordDecl();
|
||||
const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
|
||||
updateAlignment(getBaseAlignment(Layout));
|
||||
}
|
||||
PreviousBaseLayout = 0;
|
||||
|
||||
llvm::SmallPtrSet<const CXXRecordDecl *, 2> HasVtordisp =
|
||||
|
@ -2569,6 +2561,8 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBase(const CXXRecordDecl *RD,
|
|||
|
||||
// Insert the base here.
|
||||
Size = Size.RoundUpToAlignment(getBaseAlignment(Layout));
|
||||
// Update the alignment
|
||||
updateAlignment(getBaseAlignment(Layout));
|
||||
VBases.insert(
|
||||
std::make_pair(RD, ASTRecordLayout::VBaseInfo(Size, HasVtordisp)));
|
||||
Size += Layout.getNonVirtualSize();
|
||||
|
|
|
@ -163,8 +163,46 @@ CT::~CT(){}
|
|||
// CHECK-X64: | [sizeof=16, align=8
|
||||
// CHECK-X64: | nvsize=8, nvalign=8]
|
||||
|
||||
struct XA {
|
||||
XA() { printf("XA"); }
|
||||
long long ll;
|
||||
};
|
||||
struct XB : XA {
|
||||
XB() { printf("XB"); }
|
||||
virtual void foo() {}
|
||||
int b;
|
||||
};
|
||||
struct XC : virtual XB {
|
||||
XC() { printf("XC"); }
|
||||
virtual void foo() {}
|
||||
};
|
||||
|
||||
// CHECK: *** Dumping AST Record Layout
|
||||
// CHECK: 0 | struct XC
|
||||
// CHECK: 0 | (XC vbtable pointer)
|
||||
// CHECK: 4 | (vtordisp for vbase XB)
|
||||
// CHECK: 8 | struct XB (virtual base)
|
||||
// CHECK: 8 | (XB vftable pointer)
|
||||
// CHECK: 16 | struct XA (base)
|
||||
// CHECK: 16 | long long ll
|
||||
// CHECK: 24 | int b
|
||||
// CHECK: | [sizeof=32, align=8
|
||||
// CHECK: | nvsize=4, nvalign=4]
|
||||
// CHECK-X64: *** Dumping AST Record Layout
|
||||
// CHECK-X64: 0 | struct XC
|
||||
// CHECK-X64: 0 | (XC vbtable pointer)
|
||||
// CHECK-X64: 12 | (vtordisp for vbase XB)
|
||||
// CHECK-X64: 16 | struct XB (virtual base)
|
||||
// CHECK-X64: 16 | (XB vftable pointer)
|
||||
// CHECK-X64: 24 | struct XA (base)
|
||||
// CHECK-X64: 24 | long long ll
|
||||
// CHECK-X64: 32 | int b
|
||||
// CHECK-X64: | [sizeof=40, align=8
|
||||
// CHECK-X64: | nvsize=8, nvalign=8]
|
||||
|
||||
int a[
|
||||
sizeof(A)+
|
||||
sizeof(C)+
|
||||
sizeof(D)+
|
||||
sizeof(CT)];
|
||||
sizeof(CT)+
|
||||
sizeof(XC)];
|
||||
|
|
Loading…
Reference in New Issue