'long long' requires special treatment in ms_struct

structs (impacts 32-bit only though).

llvm-svn: 131103
This commit is contained in:
Fariborz Jahanian 2011-05-09 22:03:17 +00:00
parent 5d1d9e381e
commit 7adbed6b4d
2 changed files with 21 additions and 1 deletions

View File

@ -1286,9 +1286,15 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
Context.getTypeInfo(FD->getType());
uint64_t TypeSize = FieldInfo.first;
unsigned FieldAlign = FieldInfo.second;
// This check is needed for 'long long' in -m32 mode.
if (TypeSize > FieldAlign)
FieldAlign = TypeSize;
FieldInfo = Context.getTypeInfo(LastFD->getType());
uint64_t TypeSizeLastFD = FieldInfo.first;
unsigned FieldAlignLastFD = FieldInfo.second;
// This check is needed for 'long long' in -m32 mode.
if (TypeSizeLastFD > FieldAlignLastFD)
FieldAlignLastFD = TypeSizeLastFD;
if (TypeSizeLastFD != TypeSize) {
uint64_t UnpaddedFieldOffset =
getDataSizeInBits() - UnfilledBitsInLastByte;
@ -1382,6 +1388,10 @@ void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
uint64_t TypeSize = FieldInfo.first;
unsigned FieldAlign = FieldInfo.second;
// This check is needed for 'long long' in -m32 mode.
if (IsMsStruct && (TypeSize > FieldAlign))
FieldAlign = TypeSize;
if (ZeroLengthBitfield) {
// If a zero-length bitfield is inserted after a bitfield,
// and the alignment of the zero-length bitfield is

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -emit-llvm-only -triple x86_64-apple-darwin9 %s
// RUN: %clang_cc1 -emit-llvm-only -triple i386-apple-darwin9 %s
// rdar://8823265
#define ATTR __attribute__((__ms_struct__))
@ -37,3 +37,13 @@ typedef struct _struct_1 struct_1;
struct_1 test_struct_1 = { 18557917, 'a', 3, 'b' };
static int a1[(size_struct_1 == sizeof (struct_1)) -1];
struct ten {
long long a:3;
long long b:3;
char c;
} __attribute__ ((ms_struct));
#define size_struct_2 16
static int a2[(size_struct_2 == sizeof (struct ten)) -1];