[LLVMdev] getting pointer to CFG object for any given C program

Rajendra rks at cse.iitb.ac.in
Sun Oct 7 00:56:35 PDT 2012


Let say we have a C program, and we want to get pointer to CFG object 
for this code
in order to traverse basic blocks and do some analysis using CFG 

 From my main program main.cpp, how can I get pointer to CFG object if 
argv[1] = hello.c ?

I have seen following places among many in clang/lib or clang/include:

   - calls checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 
BugReporter &BR)
     if (CFG *cfg = mgr.getCFG(D)) call cfg->dump()

   - AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode, 
SetOfConstDecls *VisitedCallees)

   - CFG* CFG::buildCFG(const Decl *D, Stmt *Statement, ASTContext *C, 
const BuildOptions &BO) {
	CFGBuilder Builder(C, BO);
	return Builder.buildCFG(D, Statement);

I have tried to debug clang using gdb (by running r -cc1 -analyze 
-analyser-checker=Debug.DumpCFG hello.c from within gdb)

and now I know something about flow but exactly not able to figure out 
how to get pointer to CFG object in my program?

Since CFG is being built by recursive visit to AST, I cannot direct do 
anything with objects of classes such as CFG, CFGBuilder or CFGBlock.

My query may be trivial for many of you but I have spent a lot of time 
to figure this out without success.

Any help is much appreciated.



More information about the llvm-dev mailing list