This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Committed: fix regression and FAILs with "[PATCH] Don't ignore packed on char bitfields (4.0 regression)"
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: anemet at caviumnetworks dot com
- Cc: iant at google dot com, gcc-patches at gcc dot gnu dot org, nathan at codesourcery dot com
- Date: Sun, 25 Jan 2009 13:12:12 +0100
- Subject: Committed: fix regression and FAILs with "[PATCH] Don't ignore packed on char bitfields (4.0 regression)"
> From: Adam Nemet <anemet@caviumnetworks.com>
> Date: Wed, 21 Jan 2009 23:25:16 -0800
> I bootstrapped and regtested again on x86_64-linux and on mips64octeon-linux.
> I will commit this in 24 hours.
You should have made sure to test on a target which has packed
layout by default, as well as a target with #undef PCC_BITFIELD_TYPE_MATTERS.
Your patch changes nothing in the layout for a
non-PCC_BITFIELD_TYPE_MATTERS target, where it has been the same
since at least 3.2.x (which is by itself good :)
> * c-decl.c (finish_struct): Move code to set DECL_PACKED after
> DECL_BIT_FIELD is alreay known. Also inherit packed for bitfields
> regardless of their type.
> * c-common.c (handle_packed_attribute): Don't ignore packed on
> bitfields.
> * c.opt (Wpacked-bitfield-compat): New warning option.
> * stor-layout.c (place_field): Warn if offset of a field changed.
> * doc/extend.texi (packed): Mention the ABI change.
> * doc/invoke.texi (-Wpacked-bitfield-compat): Document.
> (Warning Options): Add it to the list.
>
> cp/
> * class.c (check_field_decls): Also inherit packed for bitfields
> regardless of their type.
>
> testsuite/
> * gcc.dg/bitfld-15.c, gcc.dg/bitfld-16.c,
> gcc.dg/bitfld-17.c,gcc.dg/bitfld-18.c: New tests.
> * g++.dg/ext/bitfield2.C, g++.dg/ext/bitfield3.C,
> g++.dg/ext/bitfield4.C, g++.dg/ext/bitfield5.C: New tests.
This patch caused pr17112-1.c to regress for cris-elf, and many
of the new tests FAIL, i.e.:
Running /tmp/hpautotest-gcc1/gcc/gcc/testsuite/gcc.dg/dg.exp ...
FAIL: gcc.dg/bitfld-15.c (test for warnings, line 10)
FAIL: gcc.dg/bitfld-17.c (test for warnings, line 9)
...
FAIL: gcc.dg/pr17112-1.c (test for warnings, line 9)
and
Running /tmp/hpautotest-gcc1/gcc/gcc/testsuite/g++.dg/dg.exp ...
...
FAIL: g++.dg/ext/bitfield2.C (test for warnings, line 6)
FAIL: g++.dg/ext/bitfield4.C (test for warnings, line 5)
The fix is trivial, as in the patch below. It's also obvious
for the new FAILs, but perhaps the regression,
gcc.dg/pr17112-1.c is a surprise. Since I think that warning is
bogus for a default-packed target(*), I'm happy with this
change, and since at least one maintainer seems to agree, I'm
all too eager to consider it obvious as well. Though CC:ing
Nathan, as he introduced the warning.
*) See PR38457, which I think your patch solves for the
bit-field case. (The attribute isn't ignored, it just doesn't
affect the layout.) As a bonus, got rid of all the bogus fp-bit
warnings! Still have warnings for non-bitfields, though.
Committed.
testsuite:
* gcc.dg/bitfld-15.c: Gate warning on target
pcc_bitfield_type_matters.
* gcc.dg/bitfld-17.c, g++.dg/ext/bitfield2.C,
g++.dg/ext/bitfield4.C: Likewise.
* gcc.dg/pr17112-1.c: Don't expect a warning for the packed
bitfield for any target.
Index: gcc.dg/bitfld-15.c
===================================================================
--- gcc.dg/bitfld-15.c (revision 143661)
+++ gcc.dg/bitfld-15.c (working copy)
@@ -7,6 +7,6 @@
char a:4;
char b:8;
char c:4;
-} __attribute__ ((packed)); /* { dg-message "note: Offset of packed bit-field 'b' has changed in GCC 4.4" "" } */
+} __attribute__ ((packed)); /* { dg-message "note: Offset of packed bit-field 'b' has changed in GCC 4.4" "" {?target pcc_bitfield_type_matters } } */
int assrt[sizeof (struct t) == 2 ? 1 : -1];
Index: gcc.dg/bitfld-17.c
===================================================================
--- gcc.dg/bitfld-17.c (revision 143661)
+++ gcc.dg/bitfld-17.c (working copy)
@@ -6,6 +6,6 @@
char a:4;
char b:8 __attribute__ ((packed));
char c:4;
-}; /* { dg-message "note: Offset of packed bit-field 'b' has changed in GCC 4.4" "" } */
+}; /* { dg-message "note: Offset of packed bit-field 'b' has changed in GCC 4.4" "" {?target pcc_bitfield_type_matters } } */
int assrt[sizeof (struct t) == 2 ? 1 : -1];
Index: gcc.dg/pr17112-1.c
===================================================================
--- gcc.dg/pr17112-1.c (revision 143661)
+++ gcc.dg/pr17112-1.c (working copy)
@@ -6,7 +6,7 @@
extern void abort(void);
typedef struct {
- int int24:24 __attribute__ ((packed)); /* { dg-warning "attribute ignored" "" { target { default_packed && { ! pcc_bitfield_type_matters } } } } */
+ int int24:24 __attribute__ ((packed));
} myint24;
myint24 x[3] = {
Index: g++.dg/ext/bitfield2.C
===================================================================
--- g++.dg/ext/bitfield2.C (revision 143661)
+++ g++.dg/ext/bitfield2.C (working copy)
@@ -3,7 +3,7 @@
/* { dg-options "" } */
struct t
-{ /* { dg-message "note: Offset of packed bit-field 't::b' has changed in GCC 4.4" "" } */
+{ /* { dg-message "note: Offset of packed bit-field 't::b' has changed in GCC 4.4" "" {?target pcc_bitfield_type_matters } } */
char a:4;
char b:8;
char c:4;
Index: g++.dg/ext/bitfield4.C
===================================================================
--- g++.dg/ext/bitfield4.C (revision 143661)
+++ g++.dg/ext/bitfield4.C (working copy)
@@ -2,7 +2,7 @@
/* { dg-options "" } */
struct t
-{ /* { dg-message "note: Offset of packed bit-field 't::b' has changed in GCC 4.4" "" } */
+{ /* { dg-message "note: Offset of packed bit-field 't::b' has changed in GCC 4.4" "" {?target pcc_bitfield_type_matters } } */
char a:4;
char b:8 __attribute__ ((packed));
char c:4;
brgds, H-P