[cfe-dev] Clang checker: 'beginning of function' hook?

Gábor Kozár kozargabor at gmail.com
Tue Sep 3 13:31:39 PDT 2013


Hi,



checkASTDecl is probably not what you want, because it is not meant to
be used for data-flow analysis (and that's why it doesn't give you a
CheckerContext). checkEndOfTranslationUnit is similar.



Probably what's best for you is checkPreCall. CallEvent and its derived
classes (you'll probably want to look at these in the header file
directly, because the generated doxygen documentation doesn't contain
several classes that are clearly meant to be exposed to the user)
contains all the information you'll ever want about the call.



The only catch is that I do not know if checkPreCall is called at the
beginning of the analysis - i.e. when the analyzer begins analyzing the
program. This should be fairly simple to check though.

Unless configured otherwise, Clang SA will start an analysis at every
simple function in every TU (as far as I know) - it doesn't look for
main(), partly because it can't do inter-TU analysis yet -- and that
would also be useless for e.g. libraries, or functions that are only
ever called through indirection...



Another thought: for efficiency reasons, you'll probably want to delay
initializing as long as possible. I mean, there's no point in setting
up state for a function parameter if it's never used (on a particular
code path), right? So my approach would be to only start assigning
information when there's actually something you need to store.



Similarly, you can use checkPostCall for clean-up, but you should also
consider using checkDeadSymbols to aggressively free up resources (e.g.
state associated with the dead values).



Hope this helps, and good luck!



--
Gábor Kozár
kozargabor at fastmail.fm





On Tue, Sep 3, 2013, at 21:13, Aemon Cannon wrote:

I'm working on my first Clang checker, and I would would like to setup
initial state for the symbols referred to by a function's parameters.
This is anintraprodedural analysis, and I want a clean slate for the
analysis of each function body, with some initial conditions determined
by annotations in the comments.

I'm not sure which Checker callback is appropriate for this.
checkASTDecl<FunctionDecl> seems promising, but I don't get a
CheckerContext in that callback.

Any thoughts?

Thanks,
Aemon

_______________________________________________

cfe-dev mailing list

[1]cfe-dev at cs.uiuc.edu

[2]http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

References

1. mailto:cfe-dev at cs.uiuc.edu
2. 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/20130903/cef7e9cc/attachment.html>


More information about the cfe-dev mailing list