3 ms·
The following program compiles without warnings using gcc 4.7.0. The compiler uses the undefined behavior of accessing a variable that may not have been initial
by rpearl 14y ago
The following program compiles without warnings using gcc 4.7.0. The compiler uses the undefined behavior of accessing a variable that may not have been initialized to turn the conditional into one that's always taken, and then folds it away.
https://gist.github.com/2910012 https://gist.github.com/2910012
- qznc 14y agoInteresting. Our compiler catches it, though: $ cparser -O3 -Wall -Wextra -pedantic test2.c -o uninit warning: ignoring gcc option '-pedantic' test2.c:3:6: warning: no previous declaration for 'void foo(int)' [-Wmissing-declarations] 1 warning(s) test2.c:4:6: warning: 'variable lol' might be used uninitialized [-Wuninitialized] Looking at the GCC bugtracker, there seem to be various warnings missing. http://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=uninitialized http://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=uninitia...
- plorkyeran 14y agoclang does catch this: clang -Weverything uninit.c uninit.c:3:6: warning: no previous prototype for function 'foo' [-Wmissing-prototypes] void foo(int bar) { ^ uninit.c:10:6: warning: variable 'lol' may be uninitialized when used here [-Wconditional-uninitialized] if (lol == 7) { ^~~ uninit.c:4:9: note: initialize the variable 'lol' to silence this warning int lol; ^ = 0 uninit.c:37:3: warning: no newline at end of file [-pedantic,-Wnewline-eof] */ ^ 3 warnings generated.
- rpearl 14y agoGlad to hear it--I've been looking into using clang more... This might just tip me towards it.
- antirez 14y agovalgrind: ==46592== Conditional jump or move depends on uninitialised value(s) ==46592== at 0x100000E90: foo (in ./a.out) ==46592== by 0x100000ED3: main (in ./a.out) The matter is, valgrind exists. Everything is a C deficiency that valgrind is able to overcome decently is no longer a C deficiency practically speaking.