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