gcc-2.95.2, '-O', operator '%=' gives wrong result

Neil Booth NeilB@earthling.net
Wed Sep 27 11:07:00 GMT 2000


Hi,

This looks like (another) example of a known problem GCC has with
signed chars / shorts when assigned immediate values.  There is a
testcase in GNATS.

Neil.

Krakowczyk, Andreas wrote:-
> Hi there,
> 
> The following test program gives wrong results when compiled with option
> '-O' but works fine without optimization.
> The compiler version I use is gcc-2.95.2 on mips-sni-sysv4 .
> The compiler command line is 'gcc -O test.c && ./a.out'.
> 
> This is the test program:
> 
> main () {
>     signed char a = 127;
>     signed char b = 126;
>     unsigned int c = 4294967295U;
> 
>     printf ("a =   0x%02X (%d)\n", a, a);
>     printf ("b =   0x%02X (%d)\n", b, b);
>     printf ("c = 0x%04X (%d)\n",   c, c);
> 
>     a %= b % c;
> 
>     if (a == 1)
> 	printf ("test passed, %s results in %d\n", "a %= b % c", a);
>     else
> 	printf ("test FAILED, %s results in %d\n", "a %= b % c", a);
> }


More information about the Gcc-bugs mailing list