Silent gcc 4.2.0 loop optimization bug with -O2

Andrey Chernov ache at nagual.pp.ru
Mon Jun 25 15:26:02 UTC 2007


On Mon, Jun 25, 2007 at 05:15:08PM +0200, Ed Schouten wrote:
> I did some more stripping and it turns out this is the problem
> 
> | int
> | main(int argc, char *argv[])
> | {
> |         int i;
> |         int numbers[4] = { 0xdead, 0xbeef, 0x1337, 0x4242 };
> | 
> |         for (i = 1; i <= 12; i++) {
> |                 if (i <= 4)
> |                         printf("%d: %x\n", i, numbers[i-1]);
> |                 else if (i >= 7 && i <= 9)
> |                         printf("MUST BE HERE!!! %d\n", i);
> |         }
> | }
> 
> When you increase the size of the array to 6 or higher, it does what you
> want. It clearly looks like a compiler bug; the size of the array
> shouldn't have an effect on the amount of iterations. 
> 
> You should really file a bug at GCC's to make sure this gets fixed in
> 4.2.1.

I am not familiar with gcc bugs reporting system at all. Could somebody 
running 4.2.1 snapshot tells, is it already fixed, by chance? If no, could 
sumebody fill bug report to them or provide detailed instructions how to 
do that, please?

In any case, we must change default CFLAGS from
-O2 -fno-strict-aliasing -pipe
to
-O -pipe
for -current immediately.

-- 
http://ache.pp.ru/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20070625/fbe4a40b/attachment.pgp


More information about the freebsd-current mailing list