1 /* Check that execution counts for various C constructs are reported
4 /* { dg-options "-fprofile-arcs -ftest-coverage" } */
5 /* { dg-do run { target native } } */
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) */
114 test_goto3 (int i
, int j
)
116 if (j
) goto else_
; /* count(1) */
119 if (i
) /* count(1) */
121 i
= do_something (i
);
125 else_
: /* count(1) */
126 j
= do_something (j
); /* count(2) */
127 if (j
) /* count(2) */
129 j
= 0; /* count(1) */
130 goto top
; /* count(1) */
139 goto_val
+= test_goto1 (0);
140 goto_val
+= test_goto1 (1);
141 goto_val
+= test_goto2 (3);
142 goto_val
+= test_goto2 (30);
143 goto_val
+= test_goto3 (0, 1);
146 /* Check nested if-then-else statements. */
153 test_ifelse1 (int i
, int j
)
156 if (i
) /* count(5) */
157 if (j
) /* count(3) */
158 result
= do_something (4); /* count(3) */
160 result
= do_something (1024);
162 if (j
) /* count(2) */
163 result
= do_something (1); /* count(1) */
165 result
= do_something (2); /* count(1) */
166 if (i
> j
) /* count(5) */
167 result
= do_something (result
*2); /* count(1) */
168 if (i
> 10) /* count(5) */
169 if (j
> 10) /* count(1) */
170 result
= do_something (result
*4); /* count(1) */
171 return result
; /* count(5) */
178 if (!i
) /* count(6) */
179 result
= do_something (1); /* count(1) */
180 if (i
== 1) /* count(6) */
181 result
= do_something (1024);
182 if (i
== 2) /* count(6) */
183 result
= do_something (2); /* count(3) */
184 if (i
== 3) /* count(6) */
185 return do_something (8); /* count(2) */
186 if (i
== 4) /* count(4) */
187 return do_something (2048);
188 return result
; /* count(4) */
192 test_ifelse3 (int i
, int j
)
195 if (i
> 10 && j
> i
&& j
< 20) /* count(11) */
196 result
= do_something (16); /* count(1) */
197 if (i
> 20) /* count(11) */
198 if (j
> i
) /* count(5) */
199 if (j
< 30) /* count(2) */
200 result
= do_something (32); /* count(1) */
201 if (i
== 3 || j
== 47 || i
== j
) /* count(11) */
202 result
= do_something (64); /* count(3) */
203 return result
; /* count(11) */
209 ifelse_val1
+= test_ifelse1 (0, 2);
210 ifelse_val1
+= test_ifelse1 (0, 0);
211 ifelse_val1
+= test_ifelse1 (1, 2);
212 ifelse_val1
+= test_ifelse1 (10, 2);
213 ifelse_val1
+= test_ifelse1 (11, 11);
215 ifelse_val2
+= test_ifelse2 (0);
216 ifelse_val2
+= test_ifelse2 (2);
217 ifelse_val2
+= test_ifelse2 (2);
218 ifelse_val2
+= test_ifelse2 (2);
219 ifelse_val2
+= test_ifelse2 (3);
220 ifelse_val2
+= test_ifelse2 (3);
222 ifelse_val3
+= test_ifelse3 (11, 19);
223 ifelse_val3
+= test_ifelse3 (25, 27);
224 ifelse_val3
+= test_ifelse3 (11, 22);
225 ifelse_val3
+= test_ifelse3 (11, 10);
226 ifelse_val3
+= test_ifelse3 (21, 32);
227 ifelse_val3
+= test_ifelse3 (21, 20);
228 ifelse_val3
+= test_ifelse3 (1, 2);
229 ifelse_val3
+= test_ifelse3 (32, 31);
230 ifelse_val3
+= test_ifelse3 (3, 0);
231 ifelse_val3
+= test_ifelse3 (0, 47);
232 ifelse_val3
+= test_ifelse3 (65, 65);
235 /* Check switch statements. */
237 int switch_val
, switch_m
;
240 test_switch (int i
, int j
)
242 int result
= 0; /* count(5) */
244 switch (i
) /* count(5) */
247 result
= do_something (2); /* count(1) */
248 break; /* count(1) */
250 result
= do_something (1024);
254 if (j
== 2) /* count(3) */
255 return do_something (4); /* count(1) */
256 result
= do_something (8); /* count(2) */
257 break; /* count(2) */
259 result
= do_something (32); /* count(1) */
260 switch_m
++; /* count(1) */
263 return result
; /* count(4) */
269 switch_val
+= test_switch (1, 0);
270 switch_val
+= test_switch (3, 0);
271 switch_val
+= test_switch (3, 2);
272 switch_val
+= test_switch (4, 0);
273 switch_val
+= test_switch (16, 0);
274 switch_val
+= switch_m
;
288 || (ifelse_val1
!= 31)
289 || (ifelse_val2
!= 23)
290 || (ifelse_val3
!= 246)
291 || (switch_val
!= 55)
297 /* { dg-final { run-gcov gcov-4.c } } */