-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 12/02/11 06:03, Patrice B wrote: > Sorry for the noise, the problem is already tracked here: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501 > > Le 2 décembre 2011 10:42, Patrice Bouchand <pbfwdl...@gmail.com> a > écrit : >> Hello, >> >> I suspect a regression in uninitialized value detection, but >> before opening a bug I request your advices on the following >> problem: >> >> I compile the following code : >> ---------------------------------------------------- #include >> <stdio.h> #include <stdlib.h> >> >> int main( int argc, char **argv ) { int j; int rtn; int k,t; >> >> j = atoi( argv[1] ); >> >> if ( j > 5 ) { rtn = 10; } >> >> k=t; >> >> printf("rtn = %d\n", rtn); >> >> exit(0); } ---------------------------------------------------- >> >> With gcc 4.0: >> >> bash-4.2$ gcc-4.0 -O2 -Wall ./test_gcc2.c -o test_gcc >> ./test_gcc2.c: In function 'main': ./test_gcc2.c:17: warning: 't' >> is used uninitialized in this function ./test_gcc2.c:7: warning: >> 'rtn' may be used uninitialized in this function >> >> With gcc 4.6.1, the warning on rtn disappears : >> >> bash-4.2$ gcc -O2 -Wall ./test_gcc2.c -o test_gcc >> ./test_gcc2.c: In function ‘main’: ./test_gcc2.c:8:8: attention : >> variable ‘k’ set but not used [-Wunused-but-set-variable] >> ./test_gcc2.c:17:5: attention : ‘t’ is used uninitialized in this >> function [-Wuninitialized] >> >> >> Do I need to pass special options to gcc 4.6.1 to enable this >> detection or is it a gcc problem ? The uninitialized warning for rtn is not emitted because gcc-4.6.1 optimizes the code better than gcc-4.0. It effectively realizes the value is uninitialized on one path through the CFG while on the other path RTN has the value 10.
When the uninitialized & initialized to 10 paths meet, the compiler (correctly) pretends the value for the uninitialized path is 10 as well. It then propagates the value 10 into the use of RTN in the printf statement. Thus by the time the uninitialized warning code runs all uses of the RTN variable have been eliminated leaving just a use of the constant 10. Thus you do not get a warning. jeff -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJO3TsOAAoJEBRtltQi2kC7xWEH/1JEUjYxG3ldybn4Bfsb14Vs NGefiik47GFUKKrjAvBlT6WxSLQxgBNLZ2Z97kT0dvTwsLrmI2uGAapZelmhDSSC mS3l3lAHvmcCWhIqsa4k8wodWlA3VuK8fjHNTDMD3O+UyJ/2a7OZ+ZKqvBQVGGsd KY9FYjNzF0sa66unl2pO+8OEwrwblh7uQc9Lm28J6zhzH8FHt/8E+paTdyxjVWgm 9kdPbsSrXHXZDaCcyLmUlgqzMUxBGK0FyueYW2g7LDF/pDKxU6XG+PKTGbHJtknn UPIavl0OKP33izxwaaLq6ifCTGhcLNwDt3pW3JostAghiZ1zCHX3ol3ja9pr6g4= =yomR -----END PGP SIGNATURE-----