This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/22275] [3.4/4.0/4.1/4.2 Regression] bitfield layout change (regression?)
- From: "matz at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jan 2006 22:31:29 -0000
- Subject: [Bug middle-end/22275] [3.4/4.0/4.1/4.2 Regression] bitfield layout change (regression?)
- References: <bug-22275-3760@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #28 from matz at suse dot de 2006-01-17 22:31 -------
And indeed with this testcase:
------------------------------------------------
typedef int BOOL;
typedef unsigned int UINT;
typedef struct {
BOOL fFullPathTitle:1;
BOOL fSaveLocalView:1;
BOOL fNotShell:1;
BOOL fSimpleDefault:1;
BOOL fDontShowDescBar:1;
BOOL fNewWindowMode:1;
BOOL fShowCompColor:1;
BOOL fDontPrettyNames:1;
BOOL fAdminsCreateCommonGroups:1;
UINT fUnusedFlags:7;
UINT :0;
UINT fMenuEnumFilter;
} __attribute__((packed)) CABINETSTATE;
int f[sizeof(CABINETSTATE) == 8? 1 : -1];
---------------------------------------------------
it's still broken with the patch. gcc 3.3 has size 8 on i686 and size 12
on x86-64. With some other fix to my patch (below) I get 8 and 8 (without
that fix it's 6 and 6). This
is consistent with the old #pragma pack(1) behaviour, so arguably this was
an inconsistency in 3.3, worth to be fixed, but it's still a change
in behaviour. It would be interesting to know what earlier compilers had.
The mentioned fix is ignoring zero sized bitfields also when DECL_PACKED
is set, like so:
Index: stor-layout.c
===================================================================
--- stor-layout.c (revision 107699)
+++ stor-layout.c (working copy)
@@ -337,6 +337,7 @@
/* For fields, it's a bit more complicated... */
{
bool old_user_align = DECL_USER_ALIGN (decl);
+ bool zero_bitfield = false;
if (DECL_BIT_FIELD (decl))
{
@@ -345,9 +346,9 @@
/* A zero-length bit-field affects the alignment of the next
field. */
if (integer_zerop (DECL_SIZE (decl))
- && ! DECL_PACKED (decl)
&& ! targetm.ms_bitfield_layout_p (DECL_FIELD_CONTEXT (decl)))
{
+ zero_bitfield = true;
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS)
do_type_align (type, decl);
@@ -408,6 +409,7 @@
check old_user_align instead. */
if (DECL_PACKED (decl)
&& !old_user_align
+ && !zero_bitfield
&& (DECL_NONADDRESSABLE_P (decl)
|| DECL_SIZE_UNIT (decl) == 0
|| TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
@@ -428,7 +430,7 @@
}
/* Should this be controlled by DECL_USER_ALIGN, too? */
- if (maximum_field_alignment != 0)
+ if (maximum_field_alignment != 0 && ! zero_bitfield)
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22275