Silent gcc 4.2.0 loop optimization bug with -O2

Andrey Chernov ache at
Mon Jun 25 13:23:35 UTC 2007

This is serious loop optimization bug with -O2.
I can't cut it down to the small sample, so here are simple steps to 

1) Compile/install misc/astrolog port, with or WITHOUT_X11, it does not 
(I just commit CFLAGS+=-O in its Makefile as workaround of this bug, so 
change it to CFLAGS+=-O2 to see the bug in action)

2) Run "astrolog -n -j0"
See lower right corner empty (under "Mode Power Percent")

3) Change back to CFLAGS+=-O, recompile, reinstall, run, see _filled_
lower right corner.

To the code - in the intrpret.c:ChartInfluence(), near the very end of 
the file is a basic loop like that:

for (i = 1; i <= 12; i++) {
  if (i <= 4) {
  } else if (i == 6) {
  } else if (i >= 7 && i <= 9) {
!!!!! It never goes here with -O2 !!!!!

Note: the exact example code above DOES NOT trigger the bug, as I say I 
can't cut it down to small sample, I just provide it for hint where bug 
place is.


More information about the freebsd-current mailing list