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

Anna Zaks ganna at apple.com
Wed Apr 24 11:51:30 PDT 2013


Sam, 

This looks very good! I have a couple of minor comments below. I would also like to have the CustomProgram States section move before the commit.

--- Custom Program States
-The data type(s) specified will also become the parameter and/or return type 
+The data type(s) specified will also become the parameter types and/or return type 
It would be better to present either a map or a set in the example of register with program state macros as these are the most common (in particular, a map that has a SymbolRef key)
Also, "Custom Program States" section should come after "Events Callbacks,..". 

--- Idea for a Checker
We could briefly introduce the SimpleStreamChecker and what it does at the end of Idea for a Checker section. What do you think?

--- Events, Callbacks.. section
-For each event type requested, a corresponding callback function with the name check<event> must be defined 
+For each event type requested, a corresponding callback function must be defined 
Since some functions don't start with check and "<event>" does not follow the format.. 

--- Bug Reports section
-This two classes used to construct this report are
+The two classes used to construct this report are
If the state has been updated, then the CheckerContext::addTransition function will return the ExplodedNode with the updated state.
If the state has not been updated, the ExplodedNode can be obtained by calling the CheckerContext::addTransition function with no arguments.
These two cases are more or less the same. I'd just first, describe the difference between sink and regular node(the paragraph below) and after that give the two options: addTransition and generateSink, which are essentially the same except for generating a transition to sink or a regular node. these would be my 1 & 2 option bullets. (The API names are not consistent :( )

Thanks!
Anna.

On Apr 21, 2013, at 4:55 PM, Sam Handler <samuel.handler+cfedev at gmail.com> wrote:

> 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.
> 
> <checker_dev_manual.diff>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130424/a48debda/attachment.html>


More information about the cfe-commits mailing list