http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55288



--- Comment #2 from Ryan Johnson <scovich at gmail dot com> 2012-11-12 21:11:43 
UTC ---

(In reply to comment #1)

> Why don't just initialize the variable? It seems simpler than implementing yet

> another special attribute in GCC.



In the original program, the "variable" is a largish struct, the function is

hot, and the 'valid' execution path is not the most common one. Avoiding

unnecessary initialization there has a measurable impact on performance. 



Note that, in other parts of the code that gcc understands better, the

initialization is unnecessary (no warning) and gets optimized away even if I do

have it in place... much to my chagrin once, after I did a lot of work to

refactor a complex function, only to realize that gcc emitted *exactly* the

same machine code afterward, because it had already noticed and eliminated the

dead stores. 



There's also a philosophical argument to be made... if we agree that all

warnings subject to false positives should be supressible, the current

mechanism for maybe-uninitialized is inadequate, and a variable attribute would

resolve the issue very nicely. There's precedent for this: you *could* use

#ifndef NDEBUG (or even pragma diagnostic) to avoid unused-variable warnings

for helper variables used by multiple assertions scattered over a region of

code, but setting ((unused)) on the offending variable is much easier to read

and maintain, while still allowing other unused variables to be flagged

properly.

Reply via email to