From 364a59ed8f0b3adb6a9eb9f2d687650ec1d0d8e5 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 12 Dec 2011 21:16:36 +0000 Subject: [PATCH] Fixes a bug in calculation of field offsets of ms_struct fields by just following what comment says. // rdar://10513599 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146414 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/RecordLayoutBuilder.cpp | 17 ++++++++++++++--- test/Sema/pragma-ms_struct.c | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index c92116ac6c..3e413befd8 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -1483,13 +1483,21 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) { uint64_t TypeSize = FieldInfo.first; unsigned FieldAlign = FieldInfo.second; // This check is needed for 'long long' in -m32 mode. - if (TypeSize > FieldAlign) + if (TypeSize > FieldAlign && + (Context.hasSameType(FD->getType(), + Context.UnsignedLongLongTy) + ||Context.hasSameType(FD->getType(), + Context.LongLongTy))) 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) + if (TypeSizeLastFD > FieldAlignLastFD && + (Context.hasSameType(LastFD->getType(), + Context.UnsignedLongLongTy) + || Context.hasSameType(LastFD->getType(), + Context.LongLongTy))) FieldAlignLastFD = TypeSizeLastFD; if (TypeSizeLastFD != TypeSize) { @@ -1640,7 +1648,10 @@ void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) { unsigned FieldAlign = FieldInfo.second; // This check is needed for 'long long' in -m32 mode. - if (IsMsStruct && (TypeSize > FieldAlign)) + if (IsMsStruct && (TypeSize > FieldAlign) && + (Context.hasSameType(D->getType(), + Context.UnsignedLongLongTy) + || Context.hasSameType(D->getType(), Context.LongLongTy))) FieldAlign = TypeSize; if (ZeroLengthBitfield) { diff --git a/test/Sema/pragma-ms_struct.c b/test/Sema/pragma-ms_struct.c index b2c2684c61..d76ee8bab3 100644 --- a/test/Sema/pragma-ms_struct.c +++ b/test/Sema/pragma-ms_struct.c @@ -32,3 +32,24 @@ struct S { } __attribute__((ms_struct)) t2; +// rdar://10513599 +#pragma ms_struct on + +typedef struct +{ +void *pv; +int l; +} Foo; + +typedef struct +{ +void *pv1; +Foo foo; +unsigned short fInited : 1; +void *pv2; +} PackOddity; + +#pragma ms_struct off + +static int arr[sizeof(PackOddity) == 40 ? 1 : -1]; + -- 2.40.0