Rajendra
2012-Oct-07 07:56 UTC
[LLVMdev] getting pointer to CFG object for any given C program
Hi, 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 object. 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: llvm-3.1.src/tools/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp:96 - calls checkASTCodeBody(const Decl *D, AnalysisManager& mgr, BugReporter &BR) if (CFG *cfg = mgr.getCFG(D)) call cfg->dump() llvm-3.1.src/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:472 - AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode, SetOfConstDecls *VisitedCallees) /usr/home3/rks/llvm/llvm-3.1.src/tools/clang/lib/Analysis/CFG.cpp:3166 - 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. Rajendra http://www.cse.iitb.ac.in/~rks
Duncan Sands
2012-Oct-07 13:34 UTC
[LLVMdev] getting pointer to CFG object for any given C program
Hi Rajendra, since this seems to be a question about clang and its AST, not about LLVM (which is lower level), you should send it to the clang mailing list instead. Ciao, Duncan.> 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 object. > > 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: > > llvm-3.1.src/tools/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp:96 > - calls checkASTCodeBody(const Decl *D, AnalysisManager& mgr, BugReporter &BR) > if (CFG *cfg = mgr.getCFG(D)) call cfg->dump() > > llvm-3.1.src/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:472 > - AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode, SetOfConstDecls > *VisitedCallees) > > /usr/home3/rks/llvm/llvm-3.1.src/tools/clang/lib/Analysis/CFG.cpp:3166 > - 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. > > > Rajendra > > http://www.cse.iitb.ac.in/~rks > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Sameer Sahasrabuddhe
2012-Oct-08 04:00 UTC
[LLVMdev] getting pointer to CFG object for any given C program
On Sun, 7 Oct 2012 13:26:35 +0530 Rajendra <rks at cse.iitb.ac.in> wrote:> 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 > object. > > From my main program main.cpp, how can I get pointer to CFG object > if argv[1] = hello.c ?On the off-chance that this is a newbie question, whatever you are trying to do, can it be expressed as an LLVM FunctionPass? In the LLVM IR, each function body is a CFG over basic blocks. Then you don't have to worry about how the frontend constructs the CFG. Sameer.