Clang checker: 'beginning of function' hook?


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!