1 /* Check that various C constructs are handled correctly by profile-directed
4 This test is the same as gcov-4.c. The "count" comments are left in to
5 make comparisons easier; they are ignored for this test. */
7 extern void abort (void);
9 int do_something (int i
)
14 /* Check static inline functions. */
19 unreferenced (int i
, int j
)
25 uncalled (int i
, int j
)
33 return i
+ j
; /* count(1) */
39 if (unref_val
) /* count(1) */
40 unref_val
= uncalled (1, 2);
41 unref_val
= called (unref_val
, 4); /* count(1) */
45 /* Check for loops. */
55 for_temp
= 1; /* count(3) */
56 for (i
= 0; i
< n
; i
++)
57 for_temp
++; /* count(9) */
58 return for_temp
; /* count(3) */
62 test_for2 (int m
, int n
, int o
)
65 for_temp
= 1; /* count(6) */
66 for (i
= 0; i
< n
; i
++)
67 for (j
= 0; j
< m
; j
++)
68 for (k
= 0; k
< o
; k
++)
69 for_temp
++; /* count(81) */
70 return for_temp
; /* count(6) */
76 for_val1
+= test_for1 (0);
77 for_val1
+= test_for1 (2);
78 for_val1
+= test_for1 (7);
80 for_val2
+= test_for2 (0, 0, 0);
81 for_val2
+= test_for2 (1, 0, 0);
82 for_val2
+= test_for2 (1, 3, 0);
83 for_val2
+= test_for2 (1, 3, 1);
84 for_val2
+= test_for2 (3, 1, 5);
85 for_val2
+= test_for2 (3, 7, 3);
88 /* Check the use of goto. */
96 goto lab1
; /* count(1) */
97 return 1; /* count(1) */
99 return 2; /* count(1) */
106 for (i
= 0; i
< 10; i
++) /* count(15) */
107 if (i
== f
) goto lab2
; /* count(14) */
108 return 4; /* count(1) */
110 return 8; /* count(1) */
116 goto_val
+= test_goto1 (0);
117 goto_val
+= test_goto1 (1);
118 goto_val
+= test_goto2 (3);
119 goto_val
+= test_goto2 (30);
122 /* Check nested if-then-else statements. */
129 test_ifelse1 (int i
, int j
)
132 if (i
) /* count(5) */
133 if (j
) /* count(3) */
134 result
= do_something (4); /* count(3) */
136 result
= do_something (1024);
138 if (j
) /* count(2) */
139 result
= do_something (1); /* count(1) */
141 result
= do_something (2); /* count(1) */
142 if (i
> j
) /* count(5) */
143 result
= do_something (result
*2); /* count(1) */
144 if (i
> 10) /* count(5) */
145 if (j
> 10) /* count(1) */
146 result
= do_something (result
*4); /* count(1) */
147 return result
; /* count(5) */
154 if (!i
) /* count(6) */
155 result
= do_something (1); /* count(1) */
156 if (i
== 1) /* count(6) */
157 result
= do_something (1024);
158 if (i
== 2) /* count(6) */
159 result
= do_something (2); /* count(3) */
160 if (i
== 3) /* count(6) */
161 return do_something (8); /* count(2) */
162 if (i
== 4) /* count(4) */
163 return do_something (2048);
164 return result
; /* count(4) */
168 test_ifelse3 (int i
, int j
)
171 if (i
> 10 && j
> i
&& j
< 20) /* count(11) */
172 result
= do_something (16); /* count(1) */
173 if (i
> 20) /* count(11) */
174 if (j
> i
) /* count(5) */
175 if (j
< 30) /* count(2) */
176 result
= do_something (32); /* count(1) */
177 if (i
== 3 || j
== 47 || i
== j
) /* count(11) */
178 result
= do_something (64); /* count(3) */
179 return result
; /* count(11) */
185 ifelse_val1
+= test_ifelse1 (0, 2);
186 ifelse_val1
+= test_ifelse1 (0, 0);
187 ifelse_val1
+= test_ifelse1 (1, 2);
188 ifelse_val1
+= test_ifelse1 (10, 2);
189 ifelse_val1
+= test_ifelse1 (11, 11);
191 ifelse_val2
+= test_ifelse2 (0);
192 ifelse_val2
+= test_ifelse2 (2);
193 ifelse_val2
+= test_ifelse2 (2);
194 ifelse_val2
+= test_ifelse2 (2);
195 ifelse_val2
+= test_ifelse2 (3);
196 ifelse_val2
+= test_ifelse2 (3);
198 ifelse_val3
+= test_ifelse3 (11, 19);
199 ifelse_val3
+= test_ifelse3 (25, 27);
200 ifelse_val3
+= test_ifelse3 (11, 22);
201 ifelse_val3
+= test_ifelse3 (11, 10);
202 ifelse_val3
+= test_ifelse3 (21, 32);
203 ifelse_val3
+= test_ifelse3 (21, 20);
204 ifelse_val3
+= test_ifelse3 (1, 2);
205 ifelse_val3
+= test_ifelse3 (32, 31);
206 ifelse_val3
+= test_ifelse3 (3, 0);
207 ifelse_val3
+= test_ifelse3 (0, 47);
208 ifelse_val3
+= test_ifelse3 (65, 65);
211 /* Check switch statements. */
213 int switch_val
, switch_m
;
216 test_switch (int i
, int j
)
218 int result
= 0; /* count(5) */
220 switch (i
) /* count(5) */
223 result
= do_something (2); /* count(1) */
226 result
= do_something (1024);
230 if (j
== 2) /* count(3) */
231 return do_something (4); /* count(1) */
232 result
= do_something (8); /* count(2) */
235 result
= do_something (32); /* count(1) */
236 switch_m
++; /* count(1) */
239 return result
; /* count(4) */
245 switch_val
+= test_switch (1, 0);
246 switch_val
+= test_switch (3, 0);
247 switch_val
+= test_switch (3, 2);
248 switch_val
+= test_switch (4, 0);
249 switch_val
+= test_switch (16, 0);
250 switch_val
+= switch_m
;
264 || (ifelse_val1
!= 31)
265 || (ifelse_val2
!= 23)
266 || (ifelse_val3
!= 246)
267 || (switch_val
!= 55)