[cfe-dev] new -Wuninitialized implementation in Clang

Chandler Carruth chandlerc at google.com
Thu Feb 3 19:28:23 PST 2011

On Thu, Feb 3, 2011 at 6:35 PM, Ted Kremenek <kremenek at apple.com> wrote:

> Since several checks in clang are bundled under the -Wuninitialized flag,
> there may be some argument to splitting these under separate flags.
> Is there a general desire to do this?  If so, why?

My primary desire to allow controlling this with more granularity is to help
ease and stage the rollout of these types of checks on a very large

However, I don't think having such granularity is actually in conflict with
this principle, which I agree on:

> My personal feeling is that things should be kept simple: keep a single
> -Wuninitialized flag that turns on all uninitialized variables checking.

I think we can have a pretty reasonable setup using the existing diagnostic
group infrastructure:

- one flag that turns all uninit checking on (or off with the no-...
- several flags that turn specific types / strategies on (or off with the
no-... variant)
- last flag (of either form) wins

This would allow patterns like "-Wuninitialized -Wno-foo-uninitialized" to
get everything except a specific feature that doesn't work for a project or
codebase, and "-Wno-uninitialized -Wfoo-uninitialized" to get just one type
of warning that a project cares about.

Most users should focus on the simple big switch, and never care about the

> Users can then either suppress the warning by initializing their variables
> (which I argue is cheap and overall good for code cleanliness) or use
> pragmas to shut up the warning entirely in regions of their code.  The
> latter may be a gross solution, but it is there for those who want it.

The problem in some cases isn't how you silence the warning, but the
necessity of code changes to do so. That's why I'm suggesting some flag
based controls.

Something else I'd like to explore (perhaps on a different thread) is
whether we could devise a more friendly syntax for a user to explicitly
acknowledge the lack of initialization on a variable as intentional. Pragmas
are really gross, and not a precise instrument. I'm imagining:

  HugePODStruct foo [[uninitialized]];  // Performance sensitive!

as something that can be used in those very rare cases where it matters,
without polluting the code with pragmas, and loosing the checking of other
variables that aren't so sensitive.

FWIW, I'm willing to contribute patches toward both proposals made here if
we can agree on exactly what they should look like.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110203/c3127000/attachment.html>

More information about the cfe-dev mailing list