Home | History | Annotate | Download | only in Analysis
      1 // RUN: rm -f %t
      2 // RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpDominators %s > %t 2>&1
      3 // RUN: FileCheck --input-file=%t %s
      4 
      5 // Test the DominatorsTree implementation with various control flows
      6 int test1()
      7 {
      8   int x = 6;
      9   int y = x/2;
     10   int z;
     11 
     12   while(y > 0) {
     13     if(y < x) {
     14       x = x/y;
     15       y = y-1;
     16     }else{
     17       z = x - y;
     18     }
     19     x = x - 1;
     20     x = x - 1;
     21   }
     22   z = x+y;
     23   z = 3;
     24   return 0;
     25 }
     26 
     27 // CHECK: Immediate dominance tree (Node#,IDom#):
     28 // CHECK: (0,1)
     29 // CHECK: (1,7)
     30 // CHECK: (2,3)
     31 // CHECK: (3,6)
     32 // CHECK: (4,6)
     33 // CHECK: (5,6)
     34 // CHECK: (6,7)
     35 // CHECK: (7,8)
     36 // CHECK: (8,9)
     37 // CHECK: (9,9)
     38 
     39 int test2()
     40 {
     41   int x,y,z;
     42 
     43   x = 10; y = 100;
     44   if(x > 0){
     45     y = 1;
     46   }else{
     47     while(x<=0){
     48       x++;
     49       y++;
     50     }
     51   }
     52   z = y;
     53 
     54   return 0;
     55 }
     56 
     57 // CHECK: Immediate dominance tree (Node#,IDom#):
     58 // CHECK: (0,1)
     59 // CHECK: (1,6)
     60 // CHECK: (2,3)
     61 // CHECK: (3,4)
     62 // CHECK: (4,6)
     63 // CHECK: (5,6)
     64 // CHECK: (6,7)
     65 // CHECK: (7,7)
     66 
     67 int test3()
     68 {
     69   int x,y,z;
     70 
     71   x = y = z = 1;
     72   if(x>0) {
     73     while(x>=0){
     74       while(y>=x) {
     75         x = x-1;
     76         y = y/2;
     77       }
     78     }
     79   }
     80   z = y;
     81 
     82   return 0;
     83 }
     84 
     85 // CHECK: Immediate dominance tree (Node#,IDom#):
     86 // CHECK: (0,1)
     87 // CHECK: (1,7)
     88 // CHECK: (2,5)
     89 // CHECK: (3,4)
     90 // CHECK: (4,5)
     91 // CHECK: (5,6)
     92 // CHECK: (6,7)
     93 // CHECK: (7,8)
     94 // CHECK: (8,8)
     95 
     96 int test4()
     97 {
     98   int y = 3;
     99   while(y > 0) {
    100     if(y < 3) {
    101       while(y>0)
    102         y ++;
    103     }else{
    104       while(y<10)
    105         y ++;
    106     }
    107   }
    108   return 0;
    109 }
    110 
    111 // CHECK: Immediate dominance tree (Node#,IDom#):
    112 // CHECK: (0,1)
    113 // CHECK: (1,10)
    114 // CHECK: (2,9)
    115 // CHECK: (3,4)
    116 // CHECK: (4,5)
    117 // CHECK: (5,9)
    118 // CHECK: (6,7)
    119 // CHECK: (7,8)
    120 // CHECK: (8,9)
    121 // CHECK: (9,10)
    122 // CHECK: (10,11)
    123 // CHECK: (11,12)
    124 // CHECK: (12,12)
    125 
    126 int test5()
    127 {
    128   int x,y,z,a,b,c;
    129   x = 1;
    130   y = 2;
    131   z = 3;
    132   a = 4;
    133   b = 5;
    134   c = 6;
    135   if ( x < 10 ) {
    136      if ( y < 10 ) {
    137         if ( z < 10 ) {
    138            x = 4;
    139         } else {
    140            x = 5;
    141         }
    142         a = 10;
    143      } else {
    144        x = 6;
    145      }
    146      b = 10;
    147   } else {
    148     x = 7;
    149   }
    150   c = 11;
    151   return 0;
    152 }
    153 
    154 // CHECK: Immediate dominance tree (Node#,IDom#):
    155 // CHECK: (0,1)
    156 // CHECK: (1,10)
    157 // CHECK: (2,10)
    158 // CHECK: (3,9)
    159 // CHECK: (4,9)
    160 // CHECK: (5,8)
    161 // CHECK: (6,8)
    162 // CHECK: (7,8)
    163 // CHECK: (8,9)
    164 // CHECK: (9,10)
    165 // CHECK: (10,11)
    166 // CHECK: (11,11)
    167 
    168 
    169