LC_ALL=C gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-cld --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.2 (Debian 4.3.2-1.1)
The following code #include <stdlib.h> #include <stdio.h> int main() { int i; double R4 = 0; int *activedirections; int nactive=0; int holder; activedirections = malloc(sizeof(int)); activedirections[0] = 0; nactive = 0; for (i=1; i<=1; i=i+1) { activedirections[nactive] = i; nactive = nactive + 1; } holder = activedirections[0]; printf("activedirections[0] = %i\n",activedirections[0]); printf("activedirections[0] = %i\n",activedirections[0]); printf("holder = %i\n",holder); free(activedirections); } produces the output: activedirections[0] = 0 activedirections[0] = 1 holder = 0 when compiling with (gcc version 4.3.2) gcc -O3 prog.c gcc -O2 prog.c gcc -Os prog.c and the output activedirections[0] = 1 activedirections[0] = 1 holder = 1 when compiled with -O1 or -O0 or when compiled with gcc-4.2.4 or gcc-4.1.3 on any optimization level. The latter is latter case is what I would expect. There is no compiler output in all cases. I will not paste the 1600 lines of prog.i in here and can not see how to attach the file to the report... ? -- Summary: O2, O3 and Os produce wrong code Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vierhaus at physik dot hu-berlin dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43219