[cfe-dev] [Patch] Update to Checker Development Manual

Sam Handler samuel.handler+cfedev at gmail.com
Sun Apr 21 16:55:24 PDT 2013


On Mon, Apr 15, 2013 at 1:28 PM, Anna Zaks <ganna at apple.com> wrote:

>
> On Apr 14, 2013, at 4:11 PM, Sam Handler <samuel.handler+cfedev at gmail.com>
> wrote
>
>
> Also, addTransition always has arguments.
>>
>
> I've changed it to suggest CheckerContext::getState instead of
> addTransition in cases where there are no state updates and the updated
> state (as returned by addTransition) in cases where there are state updates.
>
>
>
> That does not seem right. A node consists of a ProgramState AND a
> ProgramPoint.
>
> However I've realized that, here, my previous review comment is not
> correct. You CAN call addTransition with no arguments:
>   ExplodedNode *addTransition(ProgramStateRef State = 0,
>                               const ProgramPointTag *Tag = 0) {
>     return addTransitionImpl(State ? State : getState(), false, 0, Tag);
>   }
>
> In that case, the current ProgramState will be used. However, a new node
> will be created for the bug report. The node will be different from the
> previous node - it will be tagged to identify that it has been produced by
> the current checker. Sorry for the confusion!
>

A quick survey of the existing checkers indicates that, in cases where a
sink node or state transition is not being generated, the most popular way
to get an ExplodedNode to pass to BugReport is addTransition with no
arguments. I've changed my text to recommend this.


>  - Getting Started
>  - Static Analyzer overview   // Without the details of how states are
> represented
>  - Idea for a checker   // Also merge the current "AST Visitors" section
> into this one.
>
> Let's leave "AST Visitors" in the separate section. They are very
> different from the regular checkers. Someone learning about path sensitive
> checkers does not need to know about how to write an AST Visitor.
>

Ah, I misinterpreted that section. I read "AST Visitor" as Clang's
ASTVisitor (which could be used to implement "checks" that do not need path
analysis), not as a separate item specific to the analyzer. I now agree
that that section should be left in place (and, of course, should be
expanded at some point).


>
>   - Checker Registration
>  - Checker Skeleton
>
> Maybe rename into Checker Callbacks? That's what the new content seems to
> be.
>

Changed it to "Events, Callbacks, and Checker Class Structure". All three
are discussed, and are closely related to each other.

+<p>All of these macros take as parameters the name to be used for the
> custom
> "All of these macros take two parameters: the name to be used for the
> custom"
>

REGISTER_MAP_WITH_PROGRAMSTATE takes three parameters, hence the "type(s)".


>
> +  <li>Create a new checker implementation file, for example
> <tt>./lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp</tt>.
> +  <li>Include the following code (replacing SimpleStreamChecker with the
> name of the new checker).
> This is a bit confusing. We probably do not want people to create
> "SimpleStreamChecker.cpp" as such a file already exists. Maybe we should
> just change the name to something else throughout the manual. For example,
> we could use MySimpleStreamChecker. In that case, we would also not need to
> tell the reader to change the name, as in bullet #2 above. What do you
> think?
> We could also mention that the sample code used in the manual is based on
> the SimpleStreamChecker from the presentation.
>

I've changed the tone of this section from "this is what you do for a new
checker" to "this is what was done for SimpleStreamChecker", which matches
the tone of the other sections better. I don't think anyone will have
trouble determining what needs to be changed for their own new checkers.
However, I'm not sure how well this section reads after this change, please
review and give your opinion.

Also, would it be a good idea to have a section giving an overview of the
SimpleStreamChecker and declaring that it will be the example used
throughout the document? This would mean that we could simply say "for
SimpleStreamChecker" instead of having phrases like "for
SimpleStreamChecker, a checker that warns about improper use of file stream
APIs" throughout the document.


>
> -  There are two main decisions you need to make:
> -  <ul>
> -    <li> Which events the checker should be tracking.
> -    See <a href="
> http://clang.llvm.org/doxygen/classento_1_1CheckerDocumentation.html
> ">CheckerDocumentation</a>
> -    for the list of available checker callbacks.</li>
> -    <li> What data you want to store as part of the checker-specific
> program
> -    state. Try to minimize the checker state as much as possible. </li>
> -  </ul>
> I think it's very important to give people this high level roadmap, before
> diving into the example. Maybe this could be moved into a separate section
> in the very beginning. You can then link the first bullet to Checker
> Skeleton and the second one to Custom Program States. Maybe we could move
> this into the Idea for a Checker?
>

I've reinserted this material (with minor adjustment) in the "Idea for a
Checker" section.


>
> +the bug in the code and the program's state when this location is
> reached. This
> +is in the form of a node in the <tt>ExplodedGraph</tt>.
>
> "the bug in the code " -> "the bug in the source code "
> "and the program's state when this location is reached. This is in the
> form of a node" -> "and the <tt>ExplodedNode</tt> which encompasses the
> state of the program at the time the bug is encountered"
>

I've rewritten it to emphasize that both the program location and the
program state are contained in the ExplodedNode.



Updated and freshly rebased patch attached.

--Sam



-- 
===============================================================================
All opinions expressed in posts from this account are entirely my own, and
not
those of any present or former employer. Furthermore, I assert that all
works
contributed to the Clang project (1) were developed using no equipment,
supplies, facility or trade secrets of any such employer, (2) were developed
entirely on my own time, and (3) do not result from any work performed for
any
such employer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130421/6b17602f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: checker_dev_manual.diff
Type: application/octet-stream
Size: 18911 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130421/6b17602f/attachment.obj>


More information about the cfe-dev mailing list