[cfe-dev] new -Wuninitialized implementation in Clang
Johannes Schaub (litb)
schaub.johannes at googlemail.com
Thu Feb 3 20:27:10 PST 2011
Ted Kremenek wrote:
> My design goal for -Wuninitialized was threefold:
>
> (a) Works under -O0. Users care about seeing these warnings the most when
> they are doing their debug builds.
>
> (b) Has consistent results that are invariant of the optimization flags,
> target architecture, phases of the moon, etc.
>
> (c) Provides predictable results that are (for the most part) sound and
> complete.
>
> (d) Has marginal impact on compile time.
>
> The last three goals mean that the analysis can only do limited reasoning
> about control-dependencies, e.g.:
>
> int x;
> ...
> if (flag)
> x = ...
> ...
> if (flag)
> use(x);
>
> Inherently analyzing this code correctly requires path-sensitive analysis,
> which inherently has exponential cost in the general case. There are
> tricks where we can mitigate such algorithmic complexity for some common
> cases, but handling these control-dependencies in general is something
> that really is in the purview of the static analyzer. Amazingly, GCC
> often doesn't flag warnings in such cases, but I suspect that it is
> because GCC is silently dropping warnings in some cases where it deems it
> can't accurately reason precisely about a given variable.
>
Hmm, I would personally like to not initialize variables that I know are not
read from, as in your above code example. I personally regard it as bad
coding style to initialize variables with values not really used by the
code.
Would it be reasonable to have a flag that enables clang to try harder to
not warn in such cases? I haven't any clue on how much this slows down
clang's performance, but I think I'm willing to take a compile-time speed
drop equivalent to a -O2.
More information about the cfe-dev
mailing list