Hi,
I was wondering if there is a way to get SVal of a SubExpr with
the LocationContext at a function call.
Here is what I mean:
A function fun is declared and called like this:
Type arg; //1.
fun(Type* par){…} //2.
fun(&arg); //3.
If I wanted to detect if arg was uninitialized when the function fun is called (line 3.), I would use:
const CallEvent Call;
CheckerContext C;
Expr* argExp = Call.getArgExpr(0);
ProgramStateRef state = C.getState();
const LocationContext *LCtx = C.getLocationContext();
SVal LV = state->getSVal(argExp, LCtx);
bool FirstArgIsUndef = LV.isUndef();
FirstArgIsUndef will be false, because the address of arg does exist.
But now I want to detect if that which arg/par is pointing at is uninitialized, how would I do that?.
I started experimenting with this in CallAndMessageChecker::checkPreCall:
const Expr* argExp = Call.getArgExpr(i);
const Expr* argExpPure = argExp->IgnoreImpCasts();
if(const UnaryOperator* unOp = dyn_cast(argExpPure))
{
UnaryOperator::Opcode opc = unOp->getOpcode();
if(opc == UO_AddrOf)// ‘&’ operator
{
Expr* referencedInputArg = unOp->getSubExpr(); // in a dump() I see that this is really the argument arg (not par)
SVal refVal = state->getSVal(referencedInputArg, LCtx);
bool unknownRefVal = refVal.isUnknown();
bool validRefVal = refVal.isValid();
bool undefRefVal = refVal.isUndef();
}
}
it turns out that it will set refVal to isUnknown() instead of isUndef(). The context LCtx seems to forget that the SubExpr (that is here
arg) is uninitialized. I put this code in the CallAndMessageChecker::checkPreCall, perhaps this is the wrong place? or do I need to use the LCtx in another way so that it remembers the SVal of SubExpr too?.
/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@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.