[cfe-dev] improving detection of uninitialized arguments (the CallAndMessageChecker)

David Blaikie dblaikie at gmail.com
Fri Feb 14 08:23:08 PST 2014


On Fri, Feb 14, 2014 at 7:21 AM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> On Fri, Feb 14, 2014 at 12:41 PM, Per Viberg <Per.Viberg at evidente.se>
> wrote:
> >
> > Hi,
> >
> > I'm looking into extending the check that warns for uninitialized
> arguments.
> > Below I've described what should be detected. Any opinions on if it's a
> > useful check or potential problems/drawbacks with it?.
>

Do you have concrete examples of where this would have detected a bug in
code?


> >
> > Check: should this be detected as a warning for uninitialized
> > argument?:"warning: Function call argument is an uninitialized value"
> >
> > void doStuff(const int *p);
> > void f(void);
> >
> > void f(void) {
> >       int x;
> >       doStuff(&x);  // ← warning?
> > }
>
> doStuff() is allowed to const_cast the constness away and modify 'x'.
>

Yeah - I suspect that's acceptable, but someone would have to run the
numbers/experiments to see.

Another possible problem: what if doStuff is just storing the pointer for
later use?

int x;
set_foo(&x);
x = 3;
use_foo();

Not sure how common that would be and thus how bad the warning would be.

But even if we allow a false positive in that case, we should also
> make sure that the address of 'x' does not escape before the call.


Agreed - but we could just power this by the same logic as all the
-Wuninitialized warnings.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140214/79a34529/attachment.html>


More information about the cfe-dev mailing list