I found this problem when compiling GNU Emacs with GCC 7.1.0 and with Clang 3.9.1. GCC missed an uninitialized-variable bug that Clang correctly warned about. To reproduce the problem with GCC 7.1.0 x86-64, compile the following stripped-down test case: _Bool xg_update_scrollbar_pos (int a, int b) { _Bool hidden; if (a < b) hidden = 1; return !hidden; } using the command: gcc -O2 -Wall -S u.i GCC does not warn, even though 'hidden' is a possibly-uninitialized variable. With the same options, Clang warns about the bug.
This is a DUP of many other PRs, -fno-tree-ccp -fno-tree-vrp gives you the warning, but otherwise gcc optimises cond?value:undef to value.
(In reply to Paul Eggert from comment #0) > I found this problem when compiling GNU Emacs with GCC 7.1.0 and with Clang > 3.9.1. GCC missed an uninitialized-variable bug that Clang correctly warned > about. To reproduce the problem with GCC 7.1.0 x86-64, compile the following > stripped-down test case: > > _Bool > xg_update_scrollbar_pos (int a, int b) > { > _Bool hidden; > if (a < b) > hidden = 1; > return !hidden; > } > > using the command: > > gcc -O2 -Wall -S u.i > > GCC does not warn, even though 'hidden' is a possibly-uninitialized > variable. With the same options, Clang warns about the bug. Confirmed, the clang output is: $ /opt/local/bin/clang -c -O2 -Wall -S 80787.i 80787.i:5:7: warning: variable 'hidden' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (a < b) ^~~~~ 80787.i:7:11: note: uninitialized use occurs here return !hidden; ^~~~~~ 80787.i:5:3: note: remove the 'if' if its condition is always true if (a < b) ^~~~~~~~~~ 80787.i:4:15: note: initialize the variable 'hidden' to silence this warning _Bool hidden; ^ = 0 1 warning generated. $
(In reply to Marc Glisse from comment #1) > This is a DUP of many other PRs, -fno-tree-ccp -fno-tree-vrp gives you the > warning, but otherwise gcc optimises cond?value:undef to value. *** This bug has been marked as a duplicate of bug 18501 ***