https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89230
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |alias CC| |msebor at gcc dot gnu.org Depends on| |81776 --- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> --- Making GCC aware that printf doesn't modify memory (at least not without %n in the format string, or without addresses in its argument list) is the subject of pr81776. It's hard to tell for sure without more context but a similar (if not the same) problem can be reproduced in the following test case. Uncommenting the attribute makes the warning go away because it tells GCC that the pointer returned from f() and assigned to q does not alias any object in memory, so printf cannot clobber what it points to. With the test case below, I could confirm this bug as a dependency of pr81776. But if your case is different then as Andrew requests, please try to reduce it to a small reproducible test case to show us what's going on there. $ cat z.c && gcc -O2 -S -Wall z.c struct S { int i, j; }; /* attribute__ ((malloc)) */ struct S* f (void); int g (void) { struct S *p = f (), *q; if (p->i || !(q = f ()) || p->j != q->i) { __builtin_printf ("%i", p->i); if (p->i) return 1; if (!q) return 2; } return 0; } z.c: In function āgā: z.c:16:9: warning: āqā may be used uninitialized in this function [-Wmaybe-uninitialized] 16 | if (!q) | ^ Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81776 [Bug 81776] missing sprintf optimization due to pointer escape analysis