[cfe-dev] Design draft: improving detection of uninitialized arguments (the CallAndMessageChecker)
Jordan Rose
jordan_rose at apple.com
Wed Feb 19 20:21:46 PST 2014
This seems sensible to me. I am worried about one source of false positives: functions that take a pointer value solely for the purpose of using the pointer as an ID. However, this will never happen with stack variables, and static variables are always initialized, so it's only heap variables where this could be a problem. We could choose to special-case that or not.
Checking "const T&" parameters as well as "const T*" makes sense to me.
Please use SVal::getAsRegion instead of getAs<loc::MemRegionVal>. In almost all cases this makes no difference today, but the latter is at least easier to read and declares intent a little better, even though it will unnecessarily check for LocAsInteger values as well.
And finally, since this is a new set of checks with potential new false positives, please make a new entry in Checkers.td for it, and parameterize CallAndMessageChecker the same way as CheckSecuritySyntaxOnly.
This could be a very useful checker. Thank you for working on it!
Jordan
On Feb 19, 2014, at 0:58 , Per Viberg <Per.Viberg at evidente.se> wrote:
> Hi,
>
> Here is a proposed design draft to implement an extension of the check that warns for uninitialized arguments.
> Any objections/opinions on this solution?.
>
> Primarily looking for comments on: interfaces I plan to use and if it's correct to put the change in CallAndMessageChecker::checkPreCall etc.
>
> The new feature is to find arguments that are pointers to uninitialized variables, i.e. detect this:
>
> void doStuff(const int *p);
> void f(void);
>
> void f(void) {
> int x;
> doStuff(&x); // ← warning "Function call argument is a pointer to uninitialized value"
> }
>
> I propose this design:
>
> 1. Extend the CallAndMessageChecker::checkPreCall to analyse the parameters in conjunction with arguments.
> 2. If argument is declared as const Type*,
> 3. but corresponding parameter is pointer to undefined value in current function call,
> 3. then generate warning "Function call argument is a pointer to uninitialized value"
>
> I am going to use mainly the following interfaces:
> SVal::getAs<loc::MemRegionVal>()
> MemRegionVal::getRegion()
> CheckerContext::&getState()
> SVal::isUndef()
> QualType::getTypePtr()
> Type::getPointeeType()
> QualType::isConstQualified()
> FunctionDecl::getParamDecl(unsigned i)
>
> any objects/opinions on the design?
>
> cheers!
> /Per
>
>
> .......................................................................................................................
> Per Viberg Senior Engineer
> Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
> Phone: +46 (0)8 402 79 00
> Mobile: +46 (0)70 912 42 52
> E-mail: Per.Viberg at evidente.se
>
> www.evidente.se
> This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
> Från: Per Viberg
> Skickat: den 14 februari 2014 13:41
> Till: Clang Dev [cfe-dev at cs.uiuc.edu]
> Ämne: improving detection of uninitialized arguments (the CallAndMessageChecker)
>
>
> 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?.
>
> 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?
> }
>
> My rationale behind the warning:
> 1. it's not possible to write to *p, because it's of type const
> 2. content of *p is uninitialized stack value, and shouldn't be used.
> 3. the value of p is of no interest, since it's an address of an stack variable.
>
> if any of the above criteria are not fulfilled, then no warning. Thus the function prototype must state pointer to const for the argument, the variable that the function is called with must be address of local/stack variable.
>
> currently, only this is detected:
>
> void doStuff2(int p);
> void g(void);
>
> void g(void) {
> int y;
> doStuff2(y); // warning: Function call argument is an uninitialized value
>
>
> /Per
>
>
>
> .......................................................................................................................
> Per Viberg Senior Engineer
> Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
> Phone: +46 (0)8 402 79 00
> Mobile: +46 (0)70 912 42 52
> E-mail: Per.Viberg at evidente.se
>
> www.evidente.se
> This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140219/10438611/attachment.html>
More information about the cfe-dev
mailing list