This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/5430: possible gcc 2.96 error in simple arithmetic statement w/ 16 & 32 bit values
- From: ksteege at dsrnet dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 19 Jan 2002 02:34:29 -0000
- Subject: c/5430: possible gcc 2.96 error in simple arithmetic statement w/ 16 & 32 bit values
- Reply-to: ksteege at dsrnet dot com
>Number: 5430
>Category: c
>Synopsis: possible gcc 2.96 error in simple arithmetic statement w/ 16 & 32 bit values
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jan 18 18:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Kevin Steege
>Release: GCC 2.96
>Organization:
>Environment:
Red Had Linux 7.1
>Description:
Not sure if this is a true compiler bug or not, but the following problem occurred when we migrated to Linux RedHat 7.1 which came with gcc 2.96. The problem did not occur with RedHat 6.2 which came with gcc 2.91.
The code line :
Result = (((my_ushort + 2) * 2) - sizeof (my_8_struct) - 4) / 2;
where Result is a unsigned 32 bit value, my_ushort is an unsigned 16 bit value set to 924, and my_8_struct is an 8 byte structure
Produces the correct result with gcc 2.91 :
(((my_ushort + 2) * 2) - sizeof (my_8_struct) - 4) / 2 = 920 = 0x398
But an incorrect value with gcc 2.96 :
(((my_ushort + 2) * 2) - sizeof (my_8_struct) - 4) / 2 = 2147484568 = 0x80000398
Obviously there is a problem with the way the compiler casts the values between 16 bit and 32 bit integers, or at least with the way I believe the compiler should cast the values.
>How-To-Repeat:
Compile attached file mytest.c & run :
gcc mytest.c
./a.out
>Fix:
The sample program contains several similar lines which work around the problem.
>Release-Note:
>Audit-Trail:
>Unformatted: