The enclosed program prints only "0" when compiled with -O2. It should print "0" and "1". I've also tried 3.2.2 and the error is present. Phil. #include <stdio.h> void f(int start) { int i, end; for (i = end = start; i <= end; ++i) { printf("%d\n", i); if (i == start) end = 1; } } int main() { f(0); return 0; }
Confirmed, only a regression on the 3.4 branch.
The compiler fails since gcc 3.0. Looks very similar to PR 17860.
Does the patch there fix it?
Subject: Re: [3.3/3.4 Regression] Bad loop optimization with -O2 On 14 Apr, bonzini at gcc dot gnu dot org wrote: > Does the patch there fix it? Alas not.
Fixed by Ulrich's patch http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00950.html http://gcc.gnu.org/ml/gcc-cvs/2005-05/msg01066.html