[cfe-dev] basic analyzer checker programstate problem

Anna Zaks ganna at apple.com
Thu Dec 13 14:36:59 PST 2012


Your understanding is correct, the map should be propagated.
Are you sure that checkBranchCondition and checkPreCall are both called? Furthermore, are you sure one is called after the other along the same path? (You might find the ExplodedGraph viewing (p ViewGraph(0)) helpful for debugging this: http://clang-analyzer.llvm.org/checker_dev_manual.html#commands.)

Also, if checking for the availability is done through a simple API call returning a bool (ex: 'is_available'), the following approach might work. Register for checkPostCall on that API and store the returned symbol. Later, when the deprecated API is used, check if the symbol (return value from the is_available call) evaluates to true. (This would be similar to how we check if fopen succeeded in the talk.)

Cheers,
Anna.
On Dec 13, 2012, at 8:11 AM, Richard <tarka.t.otter at googlemail.com> wrote:

> hi
> 
> another fairly basic question that i am having trouble with: i am trying to set some state in an analyzer checker in checkBranchCondition and then retrieve it in checkPreCall. the state is being set ok, but for some reason is never readable in successive checkPreCall callbacks, the state map always returns NULL. i thought that the ProgramState data map was supposed to propagate down the graph, is this not how it works? i can see the node that is added to the graph, so why can i not get the state that is set?
> 
> here is the code i am using, i followed some of the other checkers pretty closely, am i doing something stupid here?
> 
> void UnavailableMethodChecker::checkBranchCondition(const Stmt *Condition, CheckerContext &Ctx) const
> {
>     VersionTuple V = getAvailabilityForStmt(Condition, Ctx);
>     ProgramStateRef State = Ctx.getState();
>     SymbolRef Sym = State->getSVal(Condition, Ctx.getLocationContext()).getAsSymbol();
>     State = State->set<AvailabilityMap>(Sym, AvailabilityState(V));
>     Ctx.addTransition(State);
> }
> 
> void UnavailableMethodChecker::checkPreCall(const CallEvent &Call, CheckerContext &Ctx) const
> {
>     ...
> 
>     ProgramStateRef State = Ctx.getState();
>     AvailabilityMapTy M = State->get<AvailabilityMap>();
>     // M is always NULL here
> 
>     for (AvailabilityMapTy::iterator I = M.begin(), E = M.end(); I != E; ++I) {
>         AvailabilityState A = I->second;
>         if (A.Version >= CallVersion) {
>             return;
>         }
>     }
> 
>     ...
> }
> 
> thanks for the help.
> _______________________________________________
> 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/20121213/1a8c0b42/attachment.html>


More information about the cfe-dev mailing list