[cfe-commits] PATCH: Fix false negatives when warning about using uninitialized variables

Kaelyn Uhrain rikka at google.com
Thu Jul 14 16:33:41 PDT 2011


As reported in PR 10358, code such as:

void foo(int y) {
  int x; // Undefined.
  do {
    y+=x;
  } while (1);
}

will only trigger a warning about x being uninitialized when
-Wconditional-uninitialized because the uninitialized variables are
mistakenly marked as possibly being assigned to before use. The attached
patch makes a few tiny changes to lib/Analysis/UninitializedValues.cpp to
not  mark uninitialized variables as Initialized just to avoid cascaded
warnings. Instead it marks them as Unknown (part of the local Value enum) so
that isUninitialized() will still return false but variables don't
accidentally get marked as maybe unitialized by calls to
CFGBlockValues::mergeIntoScratch when they are definitely uninitialized
(through it being marked as Uninitialized in one packed vector and
Initialized in the other, and the two values being or'ed together to become
MayUninitialized).

The patch also fixes up the four cases in test/Sema/uninit-variables.c where
a "may be uninitialized" should rightfully be "is uninitialized".

Cheers,
Kaelyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110714/4be3183f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uninit-var-warning-fix.diff
Type: text/x-diff
Size: 3252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110714/4be3183f/attachment.diff>


More information about the cfe-commits mailing list