Red Hat Bugzilla – Bug 169654
gcc -O1 incorrect code for unsigned long long compare
Last modified: 2007-11-30 17:07:08 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
Description of problem:
The following program fails when compiled with a -O1 option.
It works correctly with -O2.
$ cat aaa.c
unsigned int z(unsigned long long a)
if (a >= 0xffffffffULL)
int main(int argc, char **argv)
$ gcc -O1 aaa.c -o aaa
$ gcc -O2 aaa.c -o aaa
$ gcc -v
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-49)
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1.gcc -O1 aaa.c -o aaa
Actual Results: z(0ULL)=ffffffff
Expected Results: z(0ULL)=0
I checked the current gcc version 4.1.0 it doesn't have this problem.
I ran into this compiling a kernel patched with the KGDB stub which
added a -O1 option. In particular the function ata_scsiop_read_cap() in drivers/scsi/libata-scsi.c is incorrectly compiled if a -O1 option is
Created attachment 119521 [details]
Backported patch that seems to fix it.
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.