https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105728
--- Comment #4 from felix-gcc at fefe dot de --- If you do have a printf that references debug_cnt, it wouldn't be removed, right? If you expect unreferenced variables to not be optimized out, you can always compile without optimizer. For local variables even that doesn't help with clang already. OTOH we do have attributes "used" and "unused". They could be extended to variables.