https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60488
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2016-08-23 00:00:00 |2021-3-26 Known to fail|7.0 |11.0 --- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> --- Reconfirming with GCC 11. The problem is that when the address of a variable escapes, because GCC doesn't track when, when the function from which it escapes calls another that might access the escaped variable, the warning (as a result of relying on the conservative assumptions the optimizers must make) assumes the called function initializes the variable. Another example of this is function h() below. The irony (and I'd say the bug) here is that the warning uses the same conservative assumptions to trigger in cases when an equivalent same situation might lead to the variable not having been initialized such as in g() below. These conflicting assumptions make the warning seem unpredictable. $ cat z.c && gcc -O2 -S -Wall z.c void f (void); int i, *p; int g (int j) { int x; if (i) // assume i is zero x = j + 1; f (); // assume call sets i if (i) return x; // issue -Wmaybe-uninitalized return i; } int h (int j) { int x; p = &x; // address of x escapes f (); // assume call sets x return x; // avoid warning here } z.c: In function ‘g’: z.c:14:12: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized] 14 | return x; // issue -Wmaybe-uninitalized | ^ z.c:7:7: note: ‘x’ was declared here 7 | int x; | ^