This is the mail archive of the
mailing list for the GCC project.
c/6677: GCC 3.1 has a bug in signed char treatment
- From: knu at iDaemons dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 16 May 2002 14:32:29 -0000
- Subject: c/6677: GCC 3.1 has a bug in signed char treatment
- Reply-to: knu at iDaemons dot org
>Synopsis: GCC 3.1 has a bug in signed char treatment
>Arrival-Date: Thu May 16 07:36:02 PDT 2002
>Release: gcc (GCC) 3.1 [FreeBSD] 20020509 (prerelease)
FreeBSD archon.local.idaemons.org 5.0-CURRENT FreeBSD 5.0-CURRENT #7: Mon May 6 01:19:19 JST 2002 firstname.lastname@example.org:/villa/work/obj/freebsd/src/villa/src/sys/ARCHON i386
gcc (GCC) 3.1 [FreeBSD] 20020509 (prerelease)
GCC 3.1 has a bug in signed char treatment. See below.
knu@archon% cat a.c
unsigned char i = 127;
printf("%d\n", ((char)(i << 1)));
j = ((char)(i << 1)) / 2;
j = ((char)(i << 1));
printf("%d\n", j / 2);
knu@archon% cc a.c
The second value should be equal to the third (-1). (char is signed on
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.
Changing the division from `/ 2' to `>> 1' seems to work around the
problem, but I don't know why.