Basile Starynkevitch <bas...@starynkevitch.net> writes:

> Howeer, I see a logic in needing -O2 to get some warnings.
> Optimizations are expensive, and they compute static properties of the
> source code, which are usable (& necessary and used) for additional
> warnings.

The problem that I think we've discovered over the years is that when
warnings depend on optimizations, the warnings are unstable.  It means
that as optimizations change, the warnings appear and disappear.  And
that means that as people move their code to new compiler releases, they
get unpredictable new warnings.

That can be OK when the warnings are always true positives.  However, it
is very problematic when the warnings are sometimes false positives,
because it forces people to change their code for no reason, or to
disable the warning.

It might seem to be something like an out of bounds constant array index
can not go wrong, in the sense that it can never give a false positive.
However, we have already seen that it can go wrong if the compiler does
not reliably ignore code which is not executed.

Another reason that it's problematic to have warnings depend on
optimization level is that many people develop with -O0, and we want to
give them as many true positive warnings at that level as we can.

Ian

Reply via email to