Getting function body from AST for interprocedural analysis

Good Evening!

I'm playing a little with Clang and I'm trying to do a sort of
interprocedural def-use analysis in the clang AST and I need to visit
the body of functions not defined in the current file.

I've been searching a way to do that and I see there is something to
do with Libtooling, but I can't figure out how. I see there is a
function in ClangTool called BuildASTs, but for that I need to
instantiate a CommomOptionsParser with the command line arguments,
which I don't have in the CodeGen file I'm working.

Can someone give me a light on how I can build the ASTs with the
funciton definitions and get this definition from the ASTs?


Hi Lauro,

I think you would have more luck asking on cfe-dev mailing list.
Do I understand your question correctly as wishing to do cross-translation-unit analysis?
Clang static analyzer has an experimental flag for doing that, which relies on ASTImporter library
(which tries to import AST for all included C++ files).
However, that library is known to be very brittle.

(of course if by other files you mean other *header* files, not the C++ files, then everything is much simpler,
and you should be able to get the AST from clang directly)