Invalid warnings about uninitialized variables are given when compiling the following code at -O3 with gcc 4.4.3 (I see it in 4.5 as well). If I remove the loop then the warning disappears. This is a contrived example based on binutils/dwarf.c (which errors out when building with -Werror -Wall -O3). The order of the check in the !do_loc && do_types if statement is important. Obviously, the do_types code path would be taken in both cases.
problem.c: int do_types; int do_loc; unsigned char storage[8]; void testfunc(void) { int i; int j; unsigned char array[8]; for (j = 0; j < 1; j++) { if (do_types) for (i = 0; i < 8; i++) array[i] = storage[i]; if (!do_loc && do_types) for (i = 0; i < 8; i++) storage[i] = array[i]; } } EOF prompt> gcc -c -O3 problem.c -Wall problem.c: In function testfunc: problem.c:9: warning: array[7] may be used uninitialized in this function problem.c:9: warning: array[6] may be used uninitialized in this function problem.c:9: warning: array[5] may be used uninitialized in this function problem.c:9: warning: array[4] may be used uninitialized in this function problem.c:9: warning: array[3] may be used uninitialized in this function problem.c:9: warning: array[2] may be used uninitialized in this function problem.c:9: warning: array[1] may be used uninitialized in this function problem.c:9: warning: array[0] may be used uninitialized in this function prompt> gcc -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) -- Summary: Invalid uninitialized variable warning at -O3 -Wall Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dougsemler at gmail dot com GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43736