https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105728
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Btw, any such optimization would be prone to remove 'debug_cnt' in void foo() { static int debug_cnt = 0; debug_cnt++; .. stuff .. } because here nothing depends on debug_cnt. For some printf-style debugging that might be surprising. It of course already happens for void foo() { static bool ever_reached = false; ever_reached = true; }