[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    Re: optimization/8746: gcc-3 miscompiles Linux kernel ppa driver on
From:       Carsten Haustein <chaus () rz ! uni-potsdam ! de>
Date:       2003-02-28 16:26:26
[Download RAW message or body]

Compile the testcase with: gcc -O -march=i{345}86 -o check check.c
Run the test with: check <number>, where <number> is an integer between 0
and 255 (without angle brackets). The program will "prove" that any number
in this range is less than 128, which is obviously wrong.

Some notes:
1. It is important to select one of the shown -march arguments. Only code
generated for i{345}86 and K6 family is affected. Code generated for i686
family, Pentium 4 and Athlon family works fine. This code uses the al
register for applying the bit-mask instead of eax and a different
representation of the immediate 0xf0.

2. There must not be a statement between the "and" operation and the
if-expression. Otherwise code is generated for both the "and" operation
and for testing the MSB, since the extra statement may affect the
cpu-flags. Such code works fine.

3. The value assigned to r must be examined in one or the other way.
Otherwise code for the "and" operation will be omitted and code for
testing the MSB will be generated, which leads to working code too.

--

Carsten Haustein

["check.c" (TEXT/PLAIN)]

#include <stdio.h>
int main(int argc, char *argv[]) {
   unsigned char r = (atoi(argv[1])) & 0xf0;
   if (!(r & 0x80)) printf("%u < 128\n", r);
               else printf("%u >= 128\n", r);
   return 0;
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic