http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60165
--- Comment #9 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Vincent Lefèvre from comment #8) > The -Wmaybe-uninitialized rule given in the gcc man page is (for GCC 4.8): > > -Wmaybe-uninitialized > For an automatic variable, if there exists a path from the function > entry to a use of the variable that is initialized, but there exist > some other paths for which the variable is not initialized, the > compiler emits a warning if it cannot prove the uninitialized paths > are not executed at run time. [...] > > This rule does *not* depend on the optimization level, except for the "if it > cannot prove the uninitialized paths are not executed at run time" part. > Indeed, the fact that a path exists or not is not something that depends on > the optimizations. The definition of a function changes with inlining ;-) > Concerning the "if it cannot prove the uninitialized paths are not executed > at run time" part, GCC should be able to prove more things with -O3 than > with -O2, meaning that -Wmaybe-uninitialized warnings could disappear with > -O3 compared to -O2, but generally not the opposite. > > In the original example, GCC cannot prove anything about run time, so that > according to the gcc man page, one should get a warning whatever the > optimization level. f(&i) is considered as an initialization of i. This heuristic is necessary, otherwise the number of false positives would make the warning useless. > I've another example (similar to the MPFR code): > > int fn3 (void); > void fn2 (int *p) > { > if (fn3 ()) > *p = 0; > } > int fn1 (void) > { > int c; > fn2 (&c); > return c; > } > > GCC doesn't give any "may be used uninitialized" warning (whether -O2 or -O3 > is used). This is incorrect according to the above rule. BTW, for -O3, this > is surprising because it is similar to the original example. A different optimization pass (CCP) seems to notice that the value returned is either 0 or something uninitialized and thus must be 0. Maybe there is an opportunity for a warning there (though again we need to make sure it won't cause too many false positives). I don't know why you think warnings should be so well defined. They have always been a heuristic compromise.