r197639 - [ms-abi] Update Alignment for VtorDisps
Warren Hunt
whunt at google.com
Wed Dec 18 16:43:59 PST 2013
Author: whunt
Date: Wed Dec 18 18:43:59 2013
New Revision: 197639
URL: http://llvm.org/viewvc/llvm-project?rev=197639&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/Layout/ms-x86-vtordisp.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=197639&r1=197638&r2=197639&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Dec 18 18:43:59 2013
@@ -2525,14 +2525,6 @@ void MicrosoftRecordLayoutBuilder::layou
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::layou
// 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();
Modified: cfe/trunk/test/Layout/ms-x86-vtordisp.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-vtordisp.cpp?rev=197639&r1=197638&r2=197639&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-vtordisp.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-vtordisp.cpp Wed Dec 18 18:43:59 2013
@@ -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)];
More information about the cfe-commits
mailing list