From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20574 invoked by alias); 16 May 2002 14:36:05 -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 20548 invoked by uid 71); 16 May 2002 14:36:04 -0000 Resent-Date: 16 May 2002 14:36:03 -0000 Resent-Message-ID: <20020516143603.20547.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, knu@iDaemons.org Received:(qmail 18007 invoked by uid 61); 16 May 2002 14:32:30 -0000 Message-Id:<20020516143229.18006.qmail@sources.redhat.com> Date: Thu, 16 May 2002 07:36:00 -0000 From: knu@iDaemons.org Reply-To: knu@iDaemons.org To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/6677: GCC 3.1 has a bug in signed char treatment X-SW-Source: 2002-05/txt/msg00454.txt.bz2 List-Id: >Number: 6677 >Category: c >Synopsis: GCC 3.1 has a bug in signed char treatment >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Thu May 16 07:36:02 PDT 2002 >Closed-Date: >Last-Modified: >Originator: FreeBSD-gnats-submit@freebsd.org >Release: gcc (GCC) 3.1 [FreeBSD] 20020509 (prerelease) >Organization: >Environment: FreeBSD archon.local.idaemons.org 5.0-CURRENT FreeBSD 5.0-CURRENT #7: Mon May 6 01:19:19 JST 2002 root@archon.local.idaemons.org:/villa/work/obj/freebsd/src/villa/src/sys/ARCHON i386 gcc (GCC) 3.1 [FreeBSD] 20020509 (prerelease) >Description: GCC 3.1 has a bug in signed char treatment. See below. >How-To-Repeat: knu@archon[2]% cat a.c int main(void) { unsigned char i = 127; char j; printf("%d\n", ((char)(i << 1))); j = ((char)(i << 1)) / 2; printf("%d\n", j); j = ((char)(i << 1)); printf("%d\n", j / 2); return 0; } knu@archon[2]% cc a.c knu@archon[2]% ./a.out -2 127 -1 The second value should be equal to the third (-1). (char is signed on the platform) I can reproduce this with any of -O[0-6]. With gcc 2.95.x, this test code properly results in -2, -1 and -1. >Fix: Changing the division from `/ 2' to `>> 1' seems to work around the problem, but I don't know why. >Release-Note: >Audit-Trail: >Unformatted: