From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7458 invoked by alias); 19 Jan 2002 02:36:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 7392 invoked by uid 71); 19 Jan 2002 02:36:01 -0000 Resent-Date: 19 Jan 2002 02:36:01 -0000 Resent-Message-ID: <20020119023601.7391.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, ksteege@dsrnet.com Received:(qmail 7026 invoked by uid 61); 19 Jan 2002 02:34:29 -0000 Message-Id:<20020119023429.7025.qmail@sources.redhat.com> Date: Fri, 18 Jan 2002 18:36:00 -0000 From: ksteege@dsrnet.com Reply-To: ksteege@dsrnet.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/5430: possible gcc 2.96 error in simple arithmetic statement w/ 16 & 32 bit values X-SW-Source: 2002-01/txt/msg00681.txt.bz2 List-Id: >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: