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:12:31 -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 #27 from matz at suse dot de 2006-01-17 22:12 -------
Funnily I've also looked at stor-layout.c a bit, and basically came to
a similar conclusion and patch like Steven. I agree that as per documentation
PCC_BITFIELD_TYPE_MATTERS overrides EMPTY_FIELD_BOUNDARY. But that was
also a change by Jasons patch. Formerly it just "influenced" how empty
fields are handled. Clearly it influenced it in a different way than simple
overriding.
The problem, like Steven already analyzed, is twofold:
1) maximum_field_alignment now affects also empty bitfields,
which it didn't before, because before Jason maximum_field_alignment
was evaluated before other things were taken into account, and now
it's the last thing done. That's why earlier something larger than
alignment 8 bit was possible with #pragma pack(1) at all.
2) A bug or feature in pre-3.4 lead to the ignoring of EMPTY_FIELD_ALIGNMENT
when larger than 32 in our case. Namely because the initial alignment
of 64 (as required by EMPTY_FIELD_ALIGNMENT) was overriden by the
alignment of the type of the bitfield (int here, i.e. 32 bit).
I've come up with this simple patch for the problem, which fixes the testcase
for i386 and x86-64 (in the sense of being compatible with <= 3.3) .
The idea is to simply ignore the max field alignment
for empty bitfield (hence falling back to either PCC_BITFIELD_TYPE_MATTERS
or EMPTY_FIELD_ALIGNMENT as the target requested).
This needs to be tested also with struct where the packed property is not
due to a #pragma pack(1) but rather a packed attribute, or similar.
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))
{
@@ -348,6 +349,7 @@
&& ! 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);
@@ -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