http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55985
Bug #: 55985 Summary: Misleading message about which variable 'may be used uninitialized in this function' Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: jonathan.leff...@gmail.com The problem has been reduced to the following 30 lines of code with no preprocessing required. typedef struct vtype { int type; } vtype_t; typedef struct field { int length; } field_t; typedef struct clist { char *tuple; field_t *fields; } clist_t; extern int cvint(const char *p); extern void updtypes(clist_t *clist, int ocnt, vtype_t *obind); void updtypes(clist_t *clist, int ocnt, vtype_t *obind) { char *tupstart = clist->tuple; char *savtupstart; int colsize = 0; field_t *field = clist->fields; for (int cnt = ocnt; cnt--; field++, obind++) { unsigned col_flags = 0; tupstart += colsize; colsize = cvint(tupstart+1); if (*tupstart & 1) col_flags |= 0x04; tupstart += 5; if (col_flags & 0x04) tupstart = savtupstart; } } The problem is that compilation like this refers to 'tupstart' as the uninitialized variable, not 'savtupstart'. The source file was called 'gccbug.c' for this reproduction. $ gcc-4.7.1 -O3 -Werror -Wall -g -std=c99 -c gccbug.c gccbug.c: In function ‘updtypes’: gccbug.c:20:18: error: ‘tupstart’ may be used uninitialized in this function [-Werror=maybe-uninitialized] cc1: all warnings being treated as errors $ gcc-4.7.1 -Werror -Wall -g -std=c99 -c gccbug.c gccbug.c: In function ‘updtypes’: gccbug.c:29:22: error: ‘savtupstart’ may be used uninitialized in this function [-Werror=uninitialized] cc1: all warnings being treated as errors $ The real problem is that savtupstart is not initialized. Compilation with '-v' too gives: $ gcc-4.7.1 -v -O3 -Werror -Wall -g -std=c99 -c gccbug.c Using built-in specs. COLLECT_GCC=/usr/gcc/v4.7.1/bin/gcc Target: x86_64-unknown-linux-gnu Configured with: /work4/jleffler/open.source/GCC/gcc-4.7.1/configure --prefix=/usr/gcc/v4.7.1 --with-gmp=/usr/gnu64 --with-mpfr=/usr/gnu64 -with-mpc=/usr/gnu64 Thread model: posix gcc version 4.7.1 (GCC) COLLECT_GCC_OPTIONS='-v' '-O3' '-Werror' '-Wall' '-g' '-std=c99' '-c' '-mtune=generic' '-march=x86-64' /work5/gcc/v4.7.1/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.1/cc1 -quiet -v -iprefix /work5/gcc/v4.7.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/ gccbug.c -quiet -dumpbase gccbug.c -mtune=generic -march=x86-64 -auxbase gccbug -g -O3 -Werror -Wall -std=c99 -version -o /tmp/ccYrtwtL.s GNU C (GCC) version 4.7.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.7.1, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9 GGC heuristics: --param ggc-min-expand=89 --param ggc-min-heapsize=112207 ignoring nonexistent directory "/work5/gcc/v4.7.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../x86_64-unknown-linux-gnu/include" ignoring duplicate directory "/work5/gcc/v4.7.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include" ignoring duplicate directory "/work5/gcc/v4.7.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include-fixed" ignoring nonexistent directory "/work5/gcc/v4.7.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /work5/gcc/v4.7.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include /work5/gcc/v4.7.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include-fixed /usr/local/include /work5/gcc/v4.7.1/bin/../lib/gcc/../../include /usr/include End of search list. GNU C (GCC) version 4.7.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.7.1, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9 GGC heuristics: --param ggc-min-expand=89 --param ggc-min-heapsize=112207 Compiler executable checksum: 2d58955a5e5707524f76b1886c2957fc gccbug.c: In function ‘updtypes’: gccbug.c:20:18: error: ‘tupstart’ may be used uninitialized in this function [-Werror=maybe-uninitialized] cc1: all warnings being treated as errors $ The machine where it is running, and was built, is RHEL5: $ uname -a Linux toru 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux $ (Yes, archaic...sorry about that.) The variable names and function names have been renamed from the original code; it is unlikely that anyone could spot where it comes from. The structure types have been renamed and their content minimized. The reduced code does not do anything useful. Most changes to the code seem to give the correct 'savtupstart' message; I'm sure there are changes I've not tried that don't change the erroneous output, but not all that many. Removing the call to 'cvint()' leads to successful compilation (no warning at all), while removing the test before `tupstart = savtupstart;` leads to the warning mentioning 'savtupstart'. The problem was originally spotted in a 2850 line source file which includes many files and generates over 18,000 lines of preprocessor output. The original function is just about 1030 lines in the body, plus the declaration which has more parameters and is spread over 8 lines.