This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[testcase] Failure with new bitfield patch (was Re: [RFA] Fix type of bitfields)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: rth at redhat dot com, Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 1 Feb 2002 15:34:20 +0100
- Subject: [testcase] Failure with new bitfield patch (was Re: [RFA] Fix type of bitfields)
- References: <20020128214305.GA27635@daikokuya.demon.co.uk>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Jan 28, 2002 at 09:43:05PM +0000, Neil Booth wrote:
> This patch is for the C / ObjC front ends only (C++ is another
> issue altogether). Joseph wouldn't approve it since it touches code
> outside the C front end, so I'd appreciate it if a global write privs
> person would review it.
>
> The standards require a bitfield to have a type with precision its
> width, which we don't currently do at present. This leads to various
> issues, including integer promotion bugs and missing warnings about
> overflow. These are fixed with the patch below, which will enable
> me to close PRs 2511, 3325, 3326 and 3347 (and possibly others).
>
> Bootstrapped x86 Linux without regressions; testcases for all corrected
> bugs included. Also, testcases for all bitfield-related diagnostics.
Unfortunately, this patch breaks ABI seriously (e.g. tons of hardware
drivers will stop working).
Here is a testcase, ok to commit?
ATM struct A will be 3 bytes wide while it used to be 2 bytes wide.
The problem is that with your patch at place_field time field b
has unsigned char type (while it used to have unsigned short type),
and place_field uses this to decide whether it needs to advance bitpos
to avoid spanning type's boundary:
/* A bit field may not span the unit of alignment of its type.
Advance to next boundary if necessary. */
/* ??? This code should match the code above for the
PCC_BITFIELD_TYPE_MATTERS case. */
if ((offset * BITS_PER_UNIT + bit_offset) / type_align
!= ((offset * BITS_PER_UNIT + bit_offset + field_size - 1)
/ type_align))
rli->bitpos = round_up (rli->bitpos, type_align);
Now, cannot the field types be changed in finish_struct after they all have
been placed instead of changing them early?
2002-01-02 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/bitfld-2.c: New test.
--- gcc/testsuite/gcc.c-torture/execute/bitfld-2.c.jj Thu Aug 30 22:30:55 2001
+++ gcc/testsuite/gcc.c-torture/execute/bitfld-2.c Fri Feb 1 16:31:17 2002
@@ -0,0 +1,28 @@
+/* Test whether bit field boundaries aren't advanced if bit field type
+ has alignment large enough. */
+extern void abort (void);
+extern void exit (int);
+
+struct A {
+ unsigned short a : 5;
+ unsigned short b : 5;
+ unsigned short c : 6;
+};
+
+struct B {
+ unsigned short a : 5;
+ unsigned short b : 3;
+ unsigned short c : 8;
+};
+
+int main ()
+{
+ /* If short is not at least 16 bits wide, don't test anything. */
+ if ((unsigned short) 65521 != 65521)
+ exit (0);
+
+ if (sizeof (struct A) != sizeof (struct B))
+ abort ();
+
+ exit (0);
+}
Jakub