r199172 - [ms-abi] Small Change to pack+alignment interaction.
Warren Hunt
whunt at google.com
Mon Jan 13 16:54:36 PST 2014
Author: whunt
Date: Mon Jan 13 18:54:36 2014
New Revision: 199172
URL: http://llvm.org/viewvc/llvm-project?rev=199172&view=rev
Log:
[ms-abi] Small Change to pack+alignment interaction.
This patch makes a small behavioral change to the interaction between
pack and alignment. Specifically it makes __declspec(align()) on a
field change that field's alignment without respect to pack but the
alignment change to the record alignment as a whole still obeys pack.
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=199172&r1=199171&r2=199172&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Jan 13 18:54:36 2014
@@ -2186,6 +2186,9 @@ MicrosoftRecordLayoutBuilder::getAdjuste
Context.getTypeInfoInChars(FD->getType());
if (FD->isBitField() && FD->getMaxAlignment() != 0)
Info.Alignment = std::max(Info.Alignment, FieldRequiredAlignment);
+ // Respect pragma pack.
+ if (!MaxFieldAlignment.isZero())
+ Info.Alignment = std::min(Info.Alignment, MaxFieldAlignment);
}
// Respect packed field attribute.
if (FD->hasAttr<PackedAttr>())
@@ -2197,12 +2200,12 @@ MicrosoftRecordLayoutBuilder::getAdjuste
// Capture required alignment as a side-effect.
RequiredAlignment = std::max(RequiredAlignment, FieldRequiredAlignment);
}
- // Respect pragma pack.
- if (!MaxFieldAlignment.isZero())
- Info.Alignment = std::min(Info.Alignment, MaxFieldAlignment);
// TODO: Add a Sema warning that MS ignores bitfield alignment in unions.
- if (!(FD->isBitField() && IsUnion))
+ if (!(FD->isBitField() && IsUnion)) {
Alignment = std::max(Alignment, Info.Alignment);
+ if (!MaxFieldAlignment.isZero())
+ Alignment = std::min(Alignment, MaxFieldAlignment);
+ }
return Info;
}
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=199172&r1=199171&r2=199172&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-pack-and-align.cpp Mon Jan 13 18:54:36 2014
@@ -349,6 +349,28 @@ struct JC : JB, JA { };
// CHECK-X64-NEXT: | [sizeof=4, align=4
// CHECK-X64-NEXT: | nvsize=4, nvalign=4]
+#pragma pack()
+struct KA { char a; };
+#pragma pack(1)
+struct KB : KA { __declspec(align(2)) char a; };
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct KB
+// CHECK-NEXT: 0 | struct KA (base)
+// CHECK-NEXT: 0 | char a
+// CHECK-NEXT: 2 | char a
+// CHECK-NEXT: | [sizeof=4, align=2
+// CHECK-NEXT: | nvsize=3, nvalign=2]
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64-NEXT: 0 | struct KB
+// CHECK-x64-NEXT: 0 | struct KA (base)
+// CHECK-x64-NEXT: 0 | char a
+// CHECK-x64-NEXT: 2 | char a
+// CHECK-x64-NEXT: | [sizeof=4, align=2
+// CHECK-x64-NEXT: | nvsize=3, nvalign=2]
+
int a[
sizeof(X)+
sizeof(Y)+
@@ -364,4 +386,5 @@ sizeof(YF)+
sizeof(YF)+
sizeof(D2)+
sizeof(JC)+
+sizeof(KB)+
0];
More information about the cfe-commits
mailing list