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 int do_something (int i
)
12 /* Check for loops. */
23 for (i
= 0; i
< n
; i
++) /* branch(25) */
30 test_for2 (int m
, int n
, int o
)
34 for (i
= 0; i
< n
; i
++) /* branch(30) */
36 for (j
= 0; j
< m
; j
++) /* branch(32) */
38 for (k
= 0; k
< o
; k
++) /* branch(27) */
47 for_val1
+= test_for1 (0);
48 for_val1
+= test_for1 (2);
49 for_val1
+= test_for1 (7);
51 for_val2
+= test_for2 (0, 0, 0);
52 for_val2
+= test_for2 (1, 0, 0);
53 for_val2
+= test_for2 (1, 3, 0);
54 for_val2
+= test_for2 (1, 3, 1);
55 for_val2
+= test_for2 (3, 1, 5);
56 for_val2
+= test_for2 (3, 7, 3);
59 /* Check the use of goto. */
66 if (f
) /* branch(50) */
78 for (i
= 0; i
< 10; i
++) /* branch(7) */
80 if (i
== f
) goto lab2
;
89 goto_val
+= test_goto1 (0);
90 goto_val
+= test_goto1 (1);
91 goto_val
+= test_goto2 (3);
92 goto_val
+= test_goto2 (30);
95 /* Check nested if-then-else statements. */
102 test_ifelse1 (int i
, int j
)
105 if (i
) /* branch(40) */
107 if (j
) /* branch(0) */
109 result
= do_something (4);
111 result
= do_something (1024);
113 if (j
) /* branch(50) */
115 result
= do_something (1);
117 result
= do_something (2);
118 if (i
> j
) /* branch(80) */
120 result
= do_something (result
*2);
121 if (i
> 10) /* branch(80) */
123 if (j
> 10) /* branch(100) */
124 result
= do_something (result
*4);
132 if (!i
) /* branch(83) */
134 result
= do_something (1);
135 if (i
== 1) /* branch(100) */
137 result
= do_something (1024);
138 if (i
== 2) /* branch(50) */
140 result
= do_something (2);
141 if (i
== 3) /* branch(67) */
143 return do_something (8);
144 if (i
== 4) /* branch(100) */
146 return do_something (2048);
151 test_ifelse3 (int i
, int j
)
154 if (i
> 10 && j
> i
&& j
< 20) /* branch(27 50 75) */
156 result
= do_something (16);
157 if (i
> 20) /* branch(55) */
159 if (j
> i
) /* branch(60) */
161 if (j
< 30) /* branch(50) */
163 result
= do_something (32);
164 if (i
== 3 || j
== 47 || i
== j
) /* branch(9 10 89) */
166 result
= do_something (64);
173 ifelse_val1
+= test_ifelse1 (0, 2);
174 ifelse_val1
+= test_ifelse1 (0, 0);
175 ifelse_val1
+= test_ifelse1 (1, 2);
176 ifelse_val1
+= test_ifelse1 (10, 2);
177 ifelse_val1
+= test_ifelse1 (11, 11);
179 ifelse_val2
+= test_ifelse2 (0);
180 ifelse_val2
+= test_ifelse2 (2);
181 ifelse_val2
+= test_ifelse2 (2);
182 ifelse_val2
+= test_ifelse2 (2);
183 ifelse_val2
+= test_ifelse2 (3);
184 ifelse_val2
+= test_ifelse2 (3);
186 ifelse_val3
+= test_ifelse3 (11, 19);
187 ifelse_val3
+= test_ifelse3 (25, 27);
188 ifelse_val3
+= test_ifelse3 (11, 22);
189 ifelse_val3
+= test_ifelse3 (11, 10);
190 ifelse_val3
+= test_ifelse3 (21, 32);
191 ifelse_val3
+= test_ifelse3 (21, 20);
192 ifelse_val3
+= test_ifelse3 (1, 2);
193 ifelse_val3
+= test_ifelse3 (32, 31);
194 ifelse_val3
+= test_ifelse3 (3, 0);
195 ifelse_val3
+= test_ifelse3 (0, 47);
196 ifelse_val3
+= test_ifelse3 (65, 65);
199 /* Check switch statements. */
201 int switch_val
, switch_m
;
204 test_switch (int i
, int j
)
208 switch (i
) /* branch(80 25) */
212 result
= do_something (2);
215 result
= do_something (1024);
219 if (j
== 2) /* branch(67) */
221 return do_something (4);
222 result
= do_something (8);
225 result
= do_something (32);
235 switch_val
+= test_switch (1, 0);
236 switch_val
+= test_switch (3, 0);
237 switch_val
+= test_switch (3, 2);
238 switch_val
+= test_switch (4, 0);
239 switch_val
+= test_switch (16, 0);
240 switch_val
+= switch_m
;
253 || (ifelse_val1
!= 31)
254 || (ifelse_val2
!= 23)
255 || (ifelse_val3
!= 246)
256 || (switch_val
!= 55))
261 /* { dg-final { run-gcov branches { -b gcov-4b.c } } } */