This is an archive of the discontinued LLVM Phabricator instance.

[Static Analyzer] New checker hook: checkInitialState
AbandonedPublic

Authored by xazax.hun on Nov 30 2015, 1:51 PM.

Details

Reviewers
shdnx
Summary

Adds a new analyzer hook:

ProgramStateRef checkInitialState(const EntryPointInfo& EPInfo) /* non-const */;

This allows checkers to act on entry points, set up their initial state (by returning a new state) or prevent the analyzer from continuing from this entry point (by returning nullptr). It also serves to balance the existing checkEndFunction() and checkEndAnalysis() hooks.

EntryPointInfo is currently a very simple class containing a const Decl* of the declaration being used as an entry point and a ProgramStateRef of the initial state. It can later be extended, if we want to add more information to it.

Original discussion: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20151123/143961.html and http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20151130/144002.html
Original-original discussion (very old, ~2 years ago, when the idea first came up): http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20131216/095565.html

Artem Dergachev has commented that a similar hook allowing to add multiple transitions using a CheckerContext might be more favourable:

At a glance, I wonder if it's worth it to provide a CheckerContext
inside this callback and then handle transitions properly (which would
allow the checker to split the program state at the very beginning of
the function). I cannot instantly think of a use-case (hmm, maybe
somebody would like to eagerly discriminate between a NULL and non-NULL
pointer argument of the function), but at the same time I don't see any
obvious problems with adding it, especially because it'd be hard to
change the API when the use-case appears.

That wasn't a use case I had in mind, but it might be a good idea. That would serve a more general function, and I'm thinking that its interface would look something like:

void checkEntryPoint(const Decl *D, CheckerContext &Context) const;

Other thoughts?

Diff Detail

Event Timeline

shdnx updated this revision to Diff 41427.Nov 30 2015, 1:51 PM
shdnx retitled this revision from to [Static Analyzer] New checker hook: checkInitialState.
shdnx updated this object.
shdnx added reviewers: zaks.anna, jordan_rose.
shdnx added a subscriber: cfe-commits.
NoQ added a subscriber: NoQ.Dec 1 2015, 1:05 AM

Yeah, that's what i had in mind. Additionally, Decl can be obtained as Context.getStackFrame().getDecl() (and in fact the getStackFrame() thing itself is of interest as well), so there's no need to pass it as an extra argument. On the other hand, CallEvent might be of interest to have easier access to function arguments (not sure how much sense there is in a CallEvent object corresponding to the top frame, even though values inside it are pretty obvious).

In the meantime CheckBeginFunction has been implemented separately. I think you should "abandon" this revision so it is shown as closed.

xazax.hun commandeered this revision.Mar 10 2017, 7:33 AM
xazax.hun abandoned this revision.
xazax.hun added a reviewer: shdnx.
xazax.hun removed reviewers: zaks.anna, jordan_rose.
xazax.hun removed subscribers: xazax.hun, NoQ, cfe-commits.