[cfe-dev] Dataflow analysis with LLVM/Clang

João Paulo Rechi Vita joao.vita at gmail.com
Fri Oct 17 03:21:43 PDT 2008

I was looking at Clang's source code, and I found out there are two
ways of calling my analysis:

A) Write a stand-alone program, which would link to clang's libs;
B) Add a command-line option to clang driver, which would call my analysis code.

AFAIK, my analysis code will have to do something like this:

1) Parse the source file(s), and generate the AST;
2) Generate a CFG from the AST;
3) Do a dataflow analysis over the CFG, and insert some statements on
it (which I think, in turn, modifies the AST also);
4) Re-generate C code from the modified AST;

Since steps 1, 2 and 4 are already done on clang, it seems to make
sense to go with choice B, but I couldn't find how difficult it would
be to add one command line option to the driver. One the other side,
going with A will make my code more independent of clang's driver
changes, and it seems I can copy most of step's 1 and 2 from the
driver. What do you guys think would be the best option? And also,
there is any other example of use of the Clang's Analysis engine,
besides the driver?

Thanks and regards!

João Paulo Rechi Vita
MSc Computer Science Student
Computer Engineer
IC / Unicamp

More information about the cfe-dev mailing list