https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80147
Bug ID: 80147 Summary: missing maybe-uninitialized warning on variable with no side effects Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- On the following test, GCC 6.3.0 with -Wuninitialize and -Wmaybe-uninitialized (both implied by -Wall) warns as expected in the 4 cases without optimization, but if -O is used, GCC misses the warning for j1. ---------------------------------------- void f0 (int i); static void f1 (int i) { } static void f2 (int i) { f0 (i); } void g (int b) { int i1, i2, j1, j2; f1 (i1); f2 (i2); if (b) { f1 (j1); f2 (j2); } } ---------------------------------------- The following is OK: zira% gcc -Wall -c tst.c tst.c: In function ‘g’: tst.c:8:3: warning: ‘i1’ is used uninitialized in this function [-Wuninitialize] f1 (i1); ^~~~~~~ tst.c:9:3: warning: ‘i2’ is used uninitialized in this function [-Wuninitialize] f2 (i2); ^~~~~~~ tst.c:12:7: warning: ‘j1’ may be used uninitialized in this function [-Wmaybe-uninitialized] f1 (j1); ^~~~~~~ tst.c:13:7: warning: ‘j2’ may be used uninitialized in this function [-Wmaybe-uninitialized] f2 (j2); ^~~~~~~ But the warning for j1 is missing if -O is added: zira% gcc -Wall -c tst.c -O tst.c: In function ‘g’: tst.c:8:3: warning: ‘i1’ is used uninitialized in this function [-Wuninitialize] f1 (i1); ^~~~~~~ tst.c:9:3: warning: ‘i2’ is used uninitialized in this function [-Wuninitialize] f2 (i2); ^~~~~~~ tst.c:3:26: warning: ‘j2’ may be used uninitialized in this function [-Wmaybe-uninitialized] static void f2 (int i) { f0 (i); } ^~~~~~ tst.c:7:19: note: ‘j2’ was declared here int i1, i2, j1, j2; ^~