[PATCH] D15090: [Static Analyzer] New checker hook: checkInitialState

Gábor Kozár via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 30 13:51:19 PST 2015


shdnx created this revision.
shdnx added reviewers: zaks.anna, jordan_rose.
shdnx added a subscriber: cfe-commits.

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?

http://reviews.llvm.org/D15090

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointInfo.h
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15090.41427.patch
Type: text/x-patch
Size: 8067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151130/b86c839d/attachment-0001.bin>


More information about the cfe-commits mailing list