[cfe-dev] How can I judge whether a "CFGElement" is in the for or while loop?

Jordan Rose jordan_rose at apple.com
Mon Nov 4 09:33:48 PST 2013


Hi, Shuai. Unfortunately, there's not a great answer for this. Part of the philosophical reason for that is "goto" (or even "switch"), where you can jump "into" a loop, and then possibly leave it again before even evaluating the loop condition.

The analyzer diagnostics occasionally find it useful to know this, but they're just using the ParentMap of the AnalysisDeclContext for the function to walk up from the statement to see if there's an enclosing loop.

All of that said, what do you need this for? It's possible there's a better way.
Jordan


On Nov 4, 2013, at 8:10 , Shuai Wang <wangshuai901 at gmail.com> wrote:

> Hello,
> 
> I have got the CFG and I am analysing the CFGBlock of it.
> 
> I notice that in Clang, a for loop will be divide into several basic blocks like :
> 
>             
>        for (int a = 0, int i = 0; i< 5; i++)
>                a++; 
> 
> Then we can got:
>        B1:  int a=0, int i =0;
>        B2:  i < 5;
>        B3:  i ++;
>        B4:  a++;
> 
> and so on by using clang -cc1 -analyze -analyzer-checker=debug.DumpCFG xxx.c
> 
> My question is , when a got the first CFGElement of CFGBlock by using 
> CFGBlock.front();
> How can I know this CFGElement is in the for loop?
> (Which means my current analyzing block is B2 or B3 )
> 
> Thanks,
> Shuai 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list