Correspondence between AST and the CFG

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

Correspondence between AST and the CFG

Prakash Prabhu
Hi,

I am just curious to find out whether any correspondence between AST nodes and CFG is maintained in clang ? For instance, is it possible to find out once a CFG is generated, what nodes in the CFG correspond to a CompoundStmt node in the AST ? I guess this correspondence will be blurred once more and more transformations are done the CFG, but if one is interested in only doing an analysis on the CFG based on some information available from the AST (for instance analyzing flow information on those CFG nodes that correspond to certain CompoundStmts, or certain try... catch sequences), is there a simple way to do it ?

thanks,
Prakash

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

Re: Correspondence between AST and the CFG

Ted Kremenek
Hi Prakash,

When you say "CFG", are you talking about the LLVM IR or the source-level CFGs that clang supports for some warnings and static analysis?  For the latter, the source-level CFGs are just a layer on top of the original ASTs; the elements of the basic blocks are the original AST nodes.

Ted

On Jun 24, 2010, at 7:45 AM, Prakash Prabhu wrote:

> Hi,
>
> I am just curious to find out whether any correspondence between AST nodes and CFG is maintained in clang ? For instance, is it possible to find out once a CFG is generated, what nodes in the CFG correspond to a CompoundStmt node in the AST ? I guess this correspondence will be blurred once more and more transformations are done the CFG, but if one is interested in only doing an analysis on the CFG based on some information available from the AST (for instance analyzing flow information on those CFG nodes that correspond to certain CompoundStmts, or certain try... catch sequences), is there a simple way to do it ?
>
> thanks,
> Prakash
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Correspondence between AST and the CFG

Prakash Prabhu
Hi Ted,

I meant the latter. I was earlier under the impression that the CFG class, used in clang,  was a layer over the LLVM IR. Thanks for the clarification (and also the doc: http://clang.llvm.org/docs/InternalsManual.html#CFG).

One last question: is it possible to do basic block replication (and hence the underlying AST node duplication and the resulting LLVM IR generation) using the CFG class in clang, or is it a read-only structure, meant only for analysis and not transformation ?

thanks,
Prakash

On Mon, Jun 28, 2010 at 7:08 PM, Ted Kremenek <[hidden email]> wrote:
Hi Prakash,

When you say "CFG", are you talking about the LLVM IR or the source-level CFGs that clang supports for some warnings and static analysis?  For the latter, the source-level CFGs are just a layer on top of the original ASTs; the elements of the basic blocks are the original AST nodes.

Ted

On Jun 24, 2010, at 7:45 AM, Prakash Prabhu wrote:

> Hi,
>
> I am just curious to find out whether any correspondence between AST nodes and CFG is maintained in clang ? For instance, is it possible to find out once a CFG is generated, what nodes in the CFG correspond to a CompoundStmt node in the AST ? I guess this correspondence will be blurred once more and more transformations are done the CFG, but if one is interested in only doing an analysis on the CFG based on some information available from the AST (for instance analyzing flow information on those CFG nodes that correspond to certain CompoundStmts, or certain try... catch sequences), is there a simple way to do it ?
>
> thanks,
> Prakash
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Correspondence between AST and the CFG

John McCall

On Jun 29, 2010, at 7:00 AM, Prakash Prabhu wrote:

Hi Ted,

I meant the latter. I was earlier under the impression that the CFG class, used in clang,  was a layer over the LLVM IR. Thanks for the clarification (and also the doc: http://clang.llvm.org/docs/InternalsManual.html#CFG).

One last question: is it possible to do basic block replication (and hence the underlying AST node duplication and the resulting LLVM IR generation) using the CFG class in clang, or is it a read-only structure, meant only for analysis and not transformation ?

It's meant solely for analysis;  we will eventually, but have not yet, write better APIs for transforming ASTs.

John.

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

Re: Correspondence between AST and the CFG

Ted Kremenek

On Jun 29, 2010, at 9:49 AM, John McCall wrote:


On Jun 29, 2010, at 7:00 AM, Prakash Prabhu wrote:

Hi Ted,

I meant the latter. I was earlier under the impression that the CFG class, used in clang,  was a layer over the LLVM IR. Thanks for the clarification (and also the doc: http://clang.llvm.org/docs/InternalsManual.html#CFG).

One last question: is it possible to do basic block replication (and hence the underlying AST node duplication and the resulting LLVM IR generation) using the CFG class in clang, or is it a read-only structure, meant only for analysis and not transformation ?

It's meant solely for analysis;  we will eventually, but have not yet, write better APIs for transforming ASTs.

John.

Exactly.  If you want to update the CFG for a transformed AST, just build a new CFG.  It's solely meant to encode the control-flow semantics of a provided AST.

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