From: Fariborz Jahanian Date: Fri, 6 May 2011 22:42:22 +0000 (+0000) Subject: In ms_struct structs, Establish a new alignment for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31e7f225fa3c603b84d66bc8ebdf7ed084e36e62;p=clang In ms_struct structs, Establish a new alignment for a non-bitfield following a bitfield if size of their types differ. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131032 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 49c3b58510..4466be6ca2 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -1269,15 +1269,19 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) { // ignored: else if (Context.ZeroBitfieldFollowsNonBitfield(FD, LastFD)) continue; + // FIXME. streamline these conditions into a simple one. else if (Context.BitfieldFollowsBitfield(FD, LastFD) || - Context.BitfieldFollowsNoneBitfield(FD, LastFD)) { - // Adjacent bit fields are packed into the same 1-, 2-, or + Context.BitfieldFollowsNoneBitfield(FD, LastFD) || + Context.NoneBitfieldFollowsBitfield(FD, LastFD)) { + // 1) Adjacent bit fields are packed into the same 1-, 2-, or // 4-byte allocation unit if the integral types are the same // size and if the next bit field fits into the current // allocation unit without crossing the boundary imposed by the // common alignment requirements of the bit fields. - // Also, establish a new alignment for a bitfield following + // 2) Establish a new alignment for a bitfield following // a non-bitfield if size of their types differ. + // 3) Establish a new alignment for a non-bitfield following + // a bitfield if size of their types differ. std::pair FieldInfo = Context.getTypeInfo(FD->getType()); uint64_t TypeSize = FieldInfo.first; diff --git a/test/CodeGen/ms_struct-bitfield-3.c b/test/CodeGen/ms_struct-bitfield-3.c index 96782980dc..6798602f33 100644 --- a/test/CodeGen/ms_struct-bitfield-3.c +++ b/test/CodeGen/ms_struct-bitfield-3.c @@ -22,3 +22,18 @@ typedef struct _struct_0 struct_0; struct_0 test_struct_0 = { 18557917, 17, 3, 0, 80, 6487, 93 }; static int a[(size_struct_0 == sizeof (struct_0)) -1]; + +struct _struct_1 { + int d; + unsigned char a; + unsigned short b:7; + char c; +} ATTR; + +typedef struct _struct_1 struct_1; + +#define size_struct_1 12 + +struct_1 test_struct_1 = { 18557917, 'a', 3, 'b' }; + +static int a1[(size_struct_1 == sizeof (struct_1)) -1];