From 30364d0a6450315989f6613910b09f865044a2a0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 9 May 2011 22:03:17 +0000 Subject: [PATCH] 'long long' requires special treatment in ms_struct structs (impacts 32-bit only though). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131103 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/RecordLayoutBuilder.cpp | 10 ++++++++++ test/CodeGen/ms_struct-bitfield-3.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 4466be6ca2..794ae6fdc5 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -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 diff --git a/test/CodeGen/ms_struct-bitfield-3.c b/test/CodeGen/ms_struct-bitfield-3.c index 6798602f33..0eba435914 100644 --- a/test/CodeGen/ms_struct-bitfield-3.c +++ b/test/CodeGen/ms_struct-bitfield-3.c @@ -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]; -- 2.40.0