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

Timothy J. Wood via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 24 16:31:35 PDT 2018



> On Apr 24, 2018, at 4:03 PM, Artem Dergachev <noqnoqneo at gmail.com> wrote:
> 
> 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.

Ah, I was wondering if that was the case. But trying this:

	   class Loc LV = State->getLValue(OutError, LocCtxt);
	   SVal RV = State->getSVal(LV, OutError->getType());
	   llvm::errs() << "  checking null on " << RV << "\n";
	   ConditionTruthVal IsNull = State->isNull(RV);
	    llvm::errs() << "  IsNull.isUnderconstrained() = " << IsNull.isUnderconstrained() << "\n";

On the branch where outError is NULL, I get:

  checking null on &SymRegion{reg_$1<NSError ** outError>}
  IsNull.isUnderconstrained() = 1

> 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 — looks like there is lots of good background info there!

-tim




More information about the cfe-dev mailing list