diff options
author | Warren Hunt <whunt@google.com> | 2013-12-19 00:43:59 +0000 |
---|---|---|
committer | Warren Hunt <whunt@google.com> | 2013-12-19 00:43:59 +0000 |
commit | f037bd1e7c5bcd905c1a5678ddc671cd012ec4d9 (patch) | |
tree | e4b8c5779475a49ffb0102531a46d3cd440f29a0 | |
parent | 47f3c64a48ebd5ede62a5e4d06aab8142517a4df (diff) | |
download | bcm5719-llvm-f037bd1e7c5bcd905c1a5678ddc671cd012ec4d9.tar.gz bcm5719-llvm-f037bd1e7c5bcd905c1a5678ddc671cd012ec4d9.zip |
[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
-rw-r--r-- | clang/lib/AST/RecordLayoutBuilder.cpp | 10 | ||||
-rw-r--r-- | clang/test/Layout/ms-x86-vtordisp.cpp | 40 |
2 files changed, 41 insertions, 9 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index d81fb00466f..74010ce7aa0 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -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(); diff --git a/clang/test/Layout/ms-x86-vtordisp.cpp b/clang/test/Layout/ms-x86-vtordisp.cpp index b16f09ed704..6a37eb1d1fc 100644 --- a/clang/test/Layout/ms-x86-vtordisp.cpp +++ b/clang/test/Layout/ms-x86-vtordisp.cpp @@ -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)]; |