[Bug c++/105534] -Wmaybe-uninitialized cases shouldn't suppress -Wuninitialized warnings

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon May 9 13:21:59 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105534

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note there's

  _2 = value_1(D) * x_2;

where _2 might be effectively uninitialized iff x_2 is not zero.  When x_2
is zero then _2 has a well-defined value.  So to start thinking about this
I'd do a RPO walk recording a lattice of { UNDEF, MAY_UNDEF, DEF } where
the above would be "MAY_UNDEF".  PHIs would then simply merge.

That would be enough to better distinguish may from must in case the
must diagnostic is OK for the two different variables being returned.
Otherwise that needs to be taken into account as well, maybe by tracking
which variables a value is from.  Consider

void test (int x)
{
   int value1, value2;
   return (value1 * x) + value2;
}

where we maybe use value1 uninitialized and definitely value2.

Note this all leaves open which point to diagnose - the expression closest
to the (possibly conditional and possible multiple) computations with
value1 and value2 or the expression where the first (or last?) unconditional
use appears in?


More information about the Gcc-bugs mailing list