This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
problem with long long bitfields
- To: egcs-patches at cygnus dot com
- Subject: problem with long long bitfields
- From: Herman ten Brugge <Haj dot Ten dot Brugge at net dot HCC dot nl>
- Date: Sun, 18 Oct 1998 17:04:35 +0100 (WEST)
Hello,
I found a problem with long long bitfields. The problem occurred with the
following program:
struct tmp
{
long long int pad : 12;
long long int field : 52;
};
struct tmp tmp = {0x123LL, 0x123456789ABCDLL};
The code result for the i386 is:
tmp:
.byte 0x23
.byte 0xd1
.byte 0xbc
.byte 0x9a
.byte 0x78
.byte 0x55 <--- wrong
.byte 0x34
.byte 0x12
I found the bug in output_constructor in varasm.c. The value this_time and
shift are not calculated correctly.
I also found another bug. This bug only occures on the c4x where
HOST_BITS_PER_WIDE_INT == 32. It is illegal to do a shift with this value
so I clamped the value of this_time to HOST_BITS_PER_WIDE_INT-1.
Herman.
1998-10-18 Herman A.J. ten Brugge <Haj.Ten.Brugge@net.HCC.nl>
* varasm.c (output_constructor) Fixed problem with calculating
this_time and shift for long long bitfields. Also fixed problem
with shiftcount equal to HOST_BITS_PER_WIDE_INT.
--- varasm.c.org Sun Oct 18 14:35:40 1998
+++ varasm.c Sun Oct 18 14:35:28 1998
@@ -4154,6 +4154,7 @@ output_constructor (exp, size)
(all part of the same byte). */
this_time = MIN (end_offset - next_offset,
BITS_PER_UNIT - next_bit);
+ this_time = MIN (this_time, HOST_BITS_PER_WIDE_INT-1);
if (BYTES_BIG_ENDIAN)
{
/* On big-endian machine, take the most significant bits
@@ -4165,8 +4166,7 @@ output_constructor (exp, size)
if (shift < HOST_BITS_PER_WIDE_INT
&& shift + this_time > HOST_BITS_PER_WIDE_INT)
{
- this_time -= (HOST_BITS_PER_WIDE_INT - shift);
- shift = HOST_BITS_PER_WIDE_INT;
+ this_time = (HOST_BITS_PER_WIDE_INT - shift);
}
/* Now get the bits from the appropriate constant word. */
@@ -4198,8 +4198,7 @@ output_constructor (exp, size)
if (shift < HOST_BITS_PER_WIDE_INT
&& shift + this_time > HOST_BITS_PER_WIDE_INT)
{
- this_time -= (HOST_BITS_PER_WIDE_INT - shift);
- shift = HOST_BITS_PER_WIDE_INT;
+ this_time = (HOST_BITS_PER_WIDE_INT - shift);
}
/* Now get the bits from the appropriate constant word. */
--
-------------------------------------------------------------------------
Herman ten Brugge Email: Haj.Ten.Brugge@net.HCC.nl