[cfe-dev] Checking if a ParmVarDecl is null in a Checker

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 24 16:03:03 PDT 2018


On 4/24/18 1:52 PM, Timothy J. Wood via cfe-dev wrote:
> I’m attempting to add a Checker subclass that will warn on NSError-returning functions that return failure without having written to their outError parameter.
>

+George because i heard that he was also tackling a similar idea.


> The bit I’m currently stuck on is this simple test input:
>
> 	- (BOOL)failWithError:(NSError **)outError;
> 	{
> 	  if (outError) {
> 	    *outError = [NSError errorWithDomain:@"domain" code:1 userInfo:nil];
> 	  }
> 	  (void)outError; // Added as a precaution in reference to <http://lists.llvm.org/pipermail/cfe-dev/2017-April/053510.html>
> 	  return NO;
> 	}
>
> In my `checkEndFunction` implementation, I can look up the ParmVarDecl for `outError`, but if I do something like:
>
> 	  class Loc LV = State->getLValue(OutError, LocCtxt);
> 	  ConditionTruthVal IsNull = State->isNull(LV);
>
> The IsNull returned is marked under constrained when checking the path where outError was NULL.

LV in your code would represent the address of variable "outError" on 
the stack. It will always be non-null, but that's not the value you're 
looking for. You need to load from the variable:

   SVal RV = State->getSVal(LV, OutError->getType());

...or something like that.

> Since this is my first attempt at writing a checker after reading <https://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf> and <https://clang-analyzer.llvm.org/checker_dev_manual.html>, I’m probably doing something horribly wrong (still stumbling around trying to figure out the difference between SVal/Loc/SymbolRef/MemRegion and their conversions…), so any pointers would be helpful.

You might find my old workbook moderately useful: 
https://github.com/haoNoQ/clang-analyzer-guide/releases/download/v0.1/clang-analyzer-guide-v0.1.pdf

Probably also 
http://lists.llvm.org/pipermail/cfe-dev/2017-June/054084.html because 
it's slightly more correct in some places.


>
> Thanks!
>
> -tim
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list