r213123 - MS ABI: Up the required alignment after inserting padding between vbases
David Majnemer
david.majnemer at gmail.com
Wed Jul 16 00:17:03 PDT 2014
Author: majnemer
Date: Wed Jul 16 02:16:58 2014
New Revision: 213123
URL: http://llvm.org/viewvc/llvm-project?rev=213123&view=rev
Log:
MS ABI: Up the required alignment after inserting padding between vbases
We would correctly insert sufficiently aligned padding between vbases
when our leading base was empty, however we would neglect to increase
the required alignment of the most derived class.
This fixes PR20315.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=213123&r1=213122&r2=213123&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Jul 16 02:16:58 2014
@@ -2613,8 +2613,10 @@ void MicrosoftRecordLayoutBuilder::layou
// bytes (in both 32 and 64 bits modes) and always involves rounding up to
// the required alignment, we don't know why.
if ((PreviousBaseLayout && PreviousBaseLayout->hasZeroSizedSubObject() &&
- BaseLayout.leadsWithZeroSizedBase()) || HasVtordisp)
+ BaseLayout.leadsWithZeroSizedBase()) || HasVtordisp) {
Size = Size.RoundUpToAlignment(VtorDispAlignment) + VtorDispSize;
+ RequiredAlignment = VtorDispAlignment;
+ }
// Insert the virtual base.
ElementInfo Info = getAdjustedElementInfo(BaseLayout);
CharUnits BaseOffset = Size.RoundUpToAlignment(Info.Alignment);
Modified: cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp?rev=213123&r1=213122&r2=213123&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp Wed Jul 16 02:16:58 2014
@@ -544,6 +544,60 @@ struct RE {
// CHECK-X64-NEXT: | [sizeof=1029, align=1
// CHECK-X64-NEXT: | nvsize=1029, nvalign=1]
+struct NA {};
+struct NB {};
+#pragma pack(push, 1)
+struct NC : virtual NA, virtual NB {};
+#pragma pack(pop)
+struct ND : NC {};
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct NA (empty)
+// CHECK-NEXT: | [sizeof=1, align=1
+// CHECK-NEXT: | nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct NB (empty)
+// CHECK-NEXT: | [sizeof=1, align=1
+// CHECK-NEXT: | nvsize=0, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct NC
+// CHECK-NEXT: 0 | (NC vbtable pointer)
+// CHECK-NEXT: 4 | struct NA (virtual base) (empty)
+// CHECK-NEXT: 8 | struct NB (virtual base) (empty)
+// CHECK-NEXT: | [sizeof=8, align=1
+// CHECK-NEXT: | nvsize=4, nvalign=1]
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct ND
+// CHECK-NEXT: 0 | struct NC (base)
+// CHECK-NEXT: 0 | (NC vbtable pointer)
+// CHECK-NEXT: 4 | struct NA (virtual base) (empty)
+// CHECK-NEXT: 8 | struct NB (virtual base) (empty)
+// CHECK-NEXT: | [sizeof=8, align=4
+// CHECK-NEXT: | nvsize=4, nvalign=4]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64-NEXT: 0 | struct NA (empty)
+// CHECK-X64-NEXT: | [sizeof=1, align=1
+// CHECK-X64-NEXT: | nvsize=0, nvalign=1]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64-NEXT: 0 | struct NB (empty)
+// CHECK-X64-NEXT: | [sizeof=1, align=1
+// CHECK-X64-NEXT: | nvsize=0, nvalign=1]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64-NEXT: 0 | struct NC
+// CHECK-X64-NEXT: 0 | (NC vbtable pointer)
+// CHECK-X64-NEXT: 8 | struct NA (virtual base) (empty)
+// CHECK-X64-NEXT: 12 | struct NB (virtual base) (empty)
+// CHECK-X64-NEXT: | [sizeof=12, align=1
+// CHECK-X64-NEXT: | nvsize=8, nvalign=1]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64-NEXT: 0 | struct ND
+// CHECK-X64-NEXT: 0 | struct NC (base)
+// CHECK-X64-NEXT: 0 | (NC vbtable pointer)
+// CHECK-X64-NEXT: 8 | struct NA (virtual base) (empty)
+// CHECK-X64-NEXT: 12 | struct NB (virtual base) (empty)
+// CHECK-X64-NEXT: | [sizeof=12, align=4
+// CHECK-X64-NEXT: | nvsize=8, nvalign=4]
+
int a[
sizeof(X)+
sizeof(Y)+
@@ -568,4 +622,5 @@ sizeof(RB2)+
sizeof(RB3)+
sizeof(RC)+
sizeof(RE)+
+sizeof(ND)+
0];
More information about the cfe-commits
mailing list