basic block traversal for conditions and loops

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

basic block traversal for conditions and loops

Rajendra
Hello,

I am working for static analysis of C programs and I have CFG generated
from Clang.

I want to know how to traverse basic blocks for if-else and while loop
- a common method that will work for both given a CFG.

Is there any piece of Clang code I can make use of? or any pointers?

Thank you.

- Rajendra
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: basic block traversal for conditions and loops

Rajendra
Any pointers on how to traverse CFG for loops? or How to find entry and exit point of loop?
Any clang source code where it does so?
Reply | Threaded
Open this post in threaded view
|

Re: basic block traversal for conditions and loops

Anna Zaks
CFG is a graph and llvm GraphTraits for it exist. This should allow you to use llvm graph traversal algorithms.

You could also traverse it directly by relying on the iterators of CFG and CFGBlock. For example, UninitializedValues.cpp uses such iterators:
    for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
      unsigned BlockID = Block->getBlockID();
      ...
        for (CFGBlock::const_succ_iterator I = Block->succ_begin(),
             E = Block->succ_end(); I != E; ++I) {

Unlike LLVM, we do not have any direct representation of loops in clang. However, we do have support for dominators, see Dominators.h.

You can visualize the CFG with DebugChecker, which should be mentioned in clang/docs/analyzer/DebugChecks.txt.

Anna.
On Feb 5, 2013, at 8:10 PM, Rajendra <[hidden email]> wrote:

> Any pointers on how to traverse CFG for loops? or How to find entry and exit
> point of loop?
> Any clang source code where it does so?
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/basic-block-traversal-for-conditions-and-loops-tp4030231p4030308.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev