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 for loops. */
25 for (i = 0; i < n; i++) /* branch(25) */
32 test_for2 (int m, int n, int o)
36 for (i = 0; i < n; i++) /* branch(30) */
38 for (j = 0; j < m; j++) /* branch(32) */
40 for (k = 0; k < o; k++) /* branch(27) */
49 for_val1 += test_for1 (0);
50 for_val1 += test_for1 (2);
51 for_val1 += test_for1 (7);
53 for_val2 += test_for2 (0, 0, 0);
54 for_val2 += test_for2 (1, 0, 0);
55 for_val2 += test_for2 (1, 3, 0);
56 for_val2 += test_for2 (1, 3, 1);
57 for_val2 += test_for2 (3, 1, 5);
58 for_val2 += test_for2 (3, 7, 3);
61 /* Check the use of goto. */
68 if (f) /* branch(50) */
80 for (i = 0; i < 10; i++) /* branch(7) */
82 if (i == f) goto lab2;
91 goto_val += test_goto1 (0);
92 goto_val += test_goto1 (1);
93 goto_val += test_goto2 (3);
94 goto_val += test_goto2 (30);
97 /* Check nested if-then-else statements. */
104 test_ifelse1 (int i, int j)
107 if (i) /* branch(40) */
109 if (j) /* branch(0) */
111 result = do_something (4);
113 result = do_something (1024);
115 if (j) /* branch(50) */
117 result = do_something (1);
119 result = do_something (2);
120 if (i > j) /* branch(80) */
122 result = do_something (result*2);
123 if (i > 10) /* branch(80) */
125 if (j > 10) /* branch(100) */
126 result = do_something (result*4);
134 if (!i) /* branch(83) */
136 result = do_something (1);
137 if (i == 1) /* branch(100) */
139 result = do_something (1024);
140 if (i == 2) /* branch(50) */
142 result = do_something (2);
143 if (i == 3) /* branch(67) */
145 return do_something (8);
146 if (i == 4) /* branch(100) */
148 return do_something (2048);
153 test_ifelse3 (int i, int j)
156 if (i > 10 && j > i && j < 20) /* branch(27 50 75) */
158 result = do_something (16);
159 if (i > 20) /* branch(55) */
161 if (j > i) /* branch(60) */
163 if (j < 30) /* branch(50) */
165 result = do_something (32);
166 if (i == 3 || j == 47 || i == j) /* branch(9 10 89) */
168 result = do_something (64);
175 ifelse_val1 += test_ifelse1 (0, 2);
176 ifelse_val1 += test_ifelse1 (0, 0);
177 ifelse_val1 += test_ifelse1 (1, 2);
178 ifelse_val1 += test_ifelse1 (10, 2);
179 ifelse_val1 += test_ifelse1 (11, 11);
181 ifelse_val2 += test_ifelse2 (0);
182 ifelse_val2 += test_ifelse2 (2);
183 ifelse_val2 += test_ifelse2 (2);
184 ifelse_val2 += test_ifelse2 (2);
185 ifelse_val2 += test_ifelse2 (3);
186 ifelse_val2 += test_ifelse2 (3);
188 ifelse_val3 += test_ifelse3 (11, 19);
189 ifelse_val3 += test_ifelse3 (25, 27);
190 ifelse_val3 += test_ifelse3 (11, 22);
191 ifelse_val3 += test_ifelse3 (11, 10);
192 ifelse_val3 += test_ifelse3 (21, 32);
193 ifelse_val3 += test_ifelse3 (21, 20);
194 ifelse_val3 += test_ifelse3 (1, 2);
195 ifelse_val3 += test_ifelse3 (32, 31);
196 ifelse_val3 += test_ifelse3 (3, 0);
197 ifelse_val3 += test_ifelse3 (0, 47);
198 ifelse_val3 += test_ifelse3 (65, 65);
201 /* Check switch statements. */
203 int switch_val, switch_m;
206 test_switch (int i, int j)
210 switch (i) /* branch(20 0 60 20) */
214 result = do_something (2);
217 result = do_something (1024);
221 if (j == 2) /* branch(67) */
223 return do_something (4);
224 result = do_something (8);
227 result = do_something (32);
237 switch_val += test_switch (1, 0);
238 switch_val += test_switch (3, 0);
239 switch_val += test_switch (3, 2);
240 switch_val += test_switch (4, 0);
241 switch_val += test_switch (16, 0);
242 switch_val += switch_m;
255 || (ifelse_val1 != 31)
256 || (ifelse_val2 != 23)
257 || (ifelse_val3 != 246)
258 || (switch_val != 55))
263 /* { dg-final { run-gcov branches { -b gcov-4b.c } } } */