[cfe-dev] Question on LiveVariables analysis

Ted Kremenek kremenek at apple.com
Fri Oct 7 22:10:17 PDT 2011


This is what I am seeing:

$ clang -cc1 -analyze -analyzer-checker=debug.DumpLiveVars t.c

[ B0 (live variables at block exit) ]

[ B1 (live variables at block exit) ]

[ B2 (live variables at block exit) ]
 b <t.c:2:10>
 d <t.c:2:16>

[ B3 (live variables at block exit) ]
 a <t.c:2:7>
 b <t.c:2:10>
 d <t.c:2:16>

[ B4 (live variables at block exit) ]


I also think the number of the blocks is not quite right in your example, or at least how they correspond to Clang's CFG:

$ clang -cc1 -analyze -analyzer-checker=debug.DumpCFG t.c

 [ B4 (ENTRY) ]
    Predecessors (0):
    Successors (1): B3

 [ B1 ]
      1: 4
      2: c
      3: [B1.2] = [B1.1]
      4: b
      5: [B1.4]
      6: d
      7: [B1.6]
      8: [B1.5] * [B1.7]
      9: c
     10: [B1.9]
     11: [B1.8] + [B1.10]
     12: return [B1.11];
    Predecessors (2): B2 B3
    Successors (1): B0

 [ B2 ]
      1: a
      2: [B2.1]
      3: b
      4: [B2.3]
      5: [B2.2] + [B2.4]
      6: c
      7: [B2.6] = [B2.5]
      8: 2
      9: d
     10: [B2.9] = [B2.8]
    Predecessors (1): B3
    Successors (1): B1

 [ B3 ]
      1: int a;
      2: int b;
      3: int c;
      4: int d;
      5: int x;
      6: 3
      7: a
      8: [B3.7] = [B3.6]
      9: 5
     10: b
     11: [B3.10] = [B3.9]
     12: 4
     13: d
     14: [B3.13] = [B3.12]
     15: 100
     16: x
     17: [B3.16] = [B3.15]
     18: a
     19: [B3.18]
     20: b
     21: [B3.20]
     22: [B3.19] > [B3.21]
      T: if [B3.22]
    Predecessors (1): B4
    Successors (2): B2 B1

 [ B0 (EXIT) ]
    Predecessors (1): B1
    Successors (0):


Block B3 is actually the entrance block, since the CFG is built bottom-up.

Perhaps there is something not quite right with how you are running the checkers?

On Oct 7, 2011, at 9:32 PM, Guoping Long wrote:

> Hi, 
> 
>    While LiveVariables analysis (tools/clang/lib/Analysis/LiveVariables.cpp) does not generate any output? Specifically, for this simple program:
>   1 int main(int argc, char *argv[])
>   2 {
>   3   int a,b,c,d,x;
>   4 
>   5   a = 3;   //Basic block B1
>   6   b = 5;
>   7   d = 4;
>   8   x = 100;
>   9   
>  10   if(a>b){  //Basic block B2
>  11     c = a+b;
>  12     d = 2;
>  13   }
>  14   
>  15   c = 4;   //Basic block B3
>  16   return b * d + c;
>  17 }
> This simple example is taken from this wiki page illustrating live variables analysis (http://en.wikipedia.org/wiki/Live_variable_analysis).
> Both B2 and B3 should have live variables, but the output (using LiveVariables::dumpBlockLiveness(SourceManager &)) says no live variables exist. I am trying to use this analysis as an example on how to write a good analysis algorithm for Clang, but really did not expect this behavior for this analysis.
> Anybody who knows the answer please let me know. Many thanks!!!
> 
> --------
> Guoping
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111007/b92df26e/attachment.html>


More information about the cfe-dev mailing list