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 int do_something (int i)
12 /* Check static inline functions. */
17 unreferenced (int i, int j)
23 uncalled (int i, int j)
31 return i + j; /* count(1) */
37 if (unref_val) /* count(1) */
38 unref_val = uncalled (1, 2);
39 unref_val = called (unref_val, 4); /* count(1) */
43 /* Check for loops. */
53 for_temp = 1; /* count(3) */
54 for (i = 0; i < n; i++)
55 for_temp++; /* count(9) */
56 return for_temp; /* count(3) */
60 test_for2 (int m, int n, int o)
63 for_temp = 1; /* count(6) */
64 for (i = 0; i < n; i++)
65 for (j = 0; j < m; j++)
66 for (k = 0; k < o; k++)
67 for_temp++; /* count(81) */
68 return for_temp; /* count(6) */
74 for_val1 += test_for1 (0);
75 for_val1 += test_for1 (2);
76 for_val1 += test_for1 (7);
78 for_val2 += test_for2 (0, 0, 0);
79 for_val2 += test_for2 (1, 0, 0);
80 for_val2 += test_for2 (1, 3, 0);
81 for_val2 += test_for2 (1, 3, 1);
82 for_val2 += test_for2 (3, 1, 5);
83 for_val2 += test_for2 (3, 7, 3);
86 /* Check the use of goto. */
94 goto lab1; /* count(1) */
95 return 1; /* count(1) */
97 return 2; /* count(1) */
104 for (i = 0; i < 10; i++) /* count(15) */
105 if (i == f) goto lab2; /* count(14) */
106 return 4; /* count(1) */
108 return 8; /* count(1) */
114 goto_val += test_goto1 (0);
115 goto_val += test_goto1 (1);
116 goto_val += test_goto2 (3);
117 goto_val += test_goto2 (30);
120 /* Check nested if-then-else statements. */
127 test_ifelse1 (int i, int j)
130 if (i) /* count(5) */
131 if (j) /* count(3) */
132 result = do_something (4); /* count(3) */
134 result = do_something (1024);
136 if (j) /* count(2) */
137 result = do_something (1); /* count(1) */
139 result = do_something (2); /* count(1) */
140 if (i > j) /* count(5) */
141 result = do_something (result*2); /* count(1) */
142 if (i > 10) /* count(5) */
143 if (j > 10) /* count(1) */
144 result = do_something (result*4); /* count(1) */
145 return result; /* count(5) */
152 if (!i) /* count(6) */
153 result = do_something (1); /* count(1) */
154 if (i == 1) /* count(6) */
155 result = do_something (1024);
156 if (i == 2) /* count(6) */
157 result = do_something (2); /* count(3) */
158 if (i == 3) /* count(6) */
159 return do_something (8); /* count(2) */
160 if (i == 4) /* count(4) */
161 return do_something (2048);
162 return result; /* count(4) */
166 test_ifelse3 (int i, int j)
169 if (i > 10 && j > i && j < 20) /* count(11) */
170 result = do_something (16); /* count(1) */
171 if (i > 20) /* count(11) */
172 if (j > i) /* count(5) */
173 if (j < 30) /* count(2) */
174 result = do_something (32); /* count(1) */
175 if (i == 3 || j == 47 || i == j) /* count(11) */
176 result = do_something (64); /* count(3) */
177 return result; /* count(11) */
183 ifelse_val1 += test_ifelse1 (0, 2);
184 ifelse_val1 += test_ifelse1 (0, 0);
185 ifelse_val1 += test_ifelse1 (1, 2);
186 ifelse_val1 += test_ifelse1 (10, 2);
187 ifelse_val1 += test_ifelse1 (11, 11);
189 ifelse_val2 += test_ifelse2 (0);
190 ifelse_val2 += test_ifelse2 (2);
191 ifelse_val2 += test_ifelse2 (2);
192 ifelse_val2 += test_ifelse2 (2);
193 ifelse_val2 += test_ifelse2 (3);
194 ifelse_val2 += test_ifelse2 (3);
196 ifelse_val3 += test_ifelse3 (11, 19);
197 ifelse_val3 += test_ifelse3 (25, 27);
198 ifelse_val3 += test_ifelse3 (11, 22);
199 ifelse_val3 += test_ifelse3 (11, 10);
200 ifelse_val3 += test_ifelse3 (21, 32);
201 ifelse_val3 += test_ifelse3 (21, 20);
202 ifelse_val3 += test_ifelse3 (1, 2);
203 ifelse_val3 += test_ifelse3 (32, 31);
204 ifelse_val3 += test_ifelse3 (3, 0);
205 ifelse_val3 += test_ifelse3 (0, 47);
206 ifelse_val3 += test_ifelse3 (65, 65);
209 /* Check switch statements. */
211 int switch_val, switch_m;
214 test_switch (int i, int j)
216 int result = 0; /* count(5) */
218 switch (i) /* count(5) */
221 result = do_something (2); /* count(1) */
224 result = do_something (1024);
228 if (j == 2) /* count(3) */
229 return do_something (4); /* count(1) */
230 result = do_something (8); /* count(2) */
233 result = do_something (32); /* count(1) */
234 switch_m++; /* count(1) */
237 return result; /* count(4) */
243 switch_val += test_switch (1, 0);
244 switch_val += test_switch (3, 0);
245 switch_val += test_switch (3, 2);
246 switch_val += test_switch (4, 0);
247 switch_val += test_switch (16, 0);
248 switch_val += switch_m;
262 || (ifelse_val1 != 31)
263 || (ifelse_val2 != 23)
264 || (ifelse_val3 != 246)
265 || (switch_val != 55)