1 /* Check that various C constructs (in C++) don't cause problems for
2 * profile-directed block ordering.
4 Most of this test is the same as bprob-1.c and gcov-4.c in
5 gcc.misc-tests. The "count" comments are left in to make comparisons
6 easier; they are ignored for this test. */
8 extern "C" void abort (void);
10 /* Check for loops. */
20 for_temp = 1; /* count(3) */
21 for (i = 0; i < n; i++)
22 for_temp++; /* count(9) */
23 return for_temp; /* count(3) */
27 test_for2 (int m, int n, int o)
30 for_temp = 1; /* count(6) */
31 for (i = 0; i < n; i++)
32 for (j = 0; j < m; j++)
33 for (k = 0; k < o; k++)
34 for_temp++; /* count(81) */
35 return for_temp; /* count(6) */
41 for_val1 += test_for1 (0);
42 for_val1 += test_for1 (2);
43 for_val1 += test_for1 (7);
45 for_val2 += test_for2 (0, 0, 0);
46 for_val2 += test_for2 (1, 0, 0);
47 for_val2 += test_for2 (1, 3, 0);
48 for_val2 += test_for2 (1, 3, 1);
49 for_val2 += test_for2 (3, 1, 5);
50 for_val2 += test_for2 (3, 7, 3);
53 /* Check the use of goto. */
61 goto lab1; /* count(1) */
62 return 1; /* count(1) */
64 return 2; /* count(1) */
71 for (i = 0; i < 10; i++) /* count(15) */
72 if (i == f) goto lab2; /* count(14) */
73 return 4; /* count(1) */
75 return 8; /* count(1) */
81 goto_val += test_goto1 (0);
82 goto_val += test_goto1 (1);
83 goto_val += test_goto2 (3);
84 goto_val += test_goto2 (30);
87 /* Check nested if-then-else statements. */
94 test_ifelse1 (int i, int j)
99 result = 4; /* count(3) */
103 if (j) /* count(2) */
104 result = 1; /* count(1) */
106 result = 2; /* count(1) */
107 if (i > j) /* count(5) */
108 result *= 2; /* count(1) */
109 if (i > 10) /* count(5) */
110 if (j > 10) /* count(1) */
111 result *= 4; /* count(1) */
112 return result; /* count(5) */
119 if (!i) /* count(6) */
120 result = 1; /* count(1) */
121 if (i == 1) /* count(6) */
123 if (i == 2) /* count(6) */
124 result = 2; /* count(3) */
125 if (i == 3) /* count(6) */
126 return 8; /* count(2) */
127 if (i == 4) /* count(4) */
129 return result; /* count(4) */
133 test_ifelse3 (int i, int j)
136 if (i > 10 && j > i && j < 20) /* count(11) */
137 result = 16; /* count(1) */
138 if (i > 20) /* count(11) */
139 if (j > i) /* count(5) */
140 if (j < 30) /* count(2) */
141 result = 32; /* count(1) */
142 if (i == 3 || j == 47 || i == j) /* count(11) */
143 result = 64; /* count(3) */
144 return result; /* count(11) */
150 ifelse_val1 += test_ifelse1 (0, 2);
151 ifelse_val1 += test_ifelse1 (0, 0);
152 ifelse_val1 += test_ifelse1 (1, 2);
153 ifelse_val1 += test_ifelse1 (10, 2);
154 ifelse_val1 += test_ifelse1 (11, 11);
156 ifelse_val2 += test_ifelse2 (0);
157 ifelse_val2 += test_ifelse2 (2);
158 ifelse_val2 += test_ifelse2 (2);
159 ifelse_val2 += test_ifelse2 (2);
160 ifelse_val2 += test_ifelse2 (3);
161 ifelse_val2 += test_ifelse2 (3);
163 ifelse_val3 += test_ifelse3 (11, 19);
164 ifelse_val3 += test_ifelse3 (25, 27);
165 ifelse_val3 += test_ifelse3 (11, 22);
166 ifelse_val3 += test_ifelse3 (11, 10);
167 ifelse_val3 += test_ifelse3 (21, 32);
168 ifelse_val3 += test_ifelse3 (21, 20);
169 ifelse_val3 += test_ifelse3 (1, 2);
170 ifelse_val3 += test_ifelse3 (32, 31);
171 ifelse_val3 += test_ifelse3 (3, 0);
172 ifelse_val3 += test_ifelse3 (0, 47); /* count(1) */
173 ifelse_val3 += test_ifelse3 (65, 65); /* count(1) */
176 /* Check switch statements. */
178 int switch_val, switch_m;
181 test_switch (int i, int j)
183 int result = 0; /* count(5) */
185 switch (i) /* count(5) */
188 result = 2; /* count(1) */
195 if (j == 2) /* count(3) */
196 return 4; /* count(1) */
197 result = 8; /* count(2) */
200 result = 32; /* count(1) */
201 switch_m++; /* count(1) */
204 return result; /* count(4) */
210 switch_val += test_switch (1, 0);
211 switch_val += test_switch (3, 0);
212 switch_val += test_switch (3, 2);
213 switch_val += test_switch (4, 0);
214 switch_val += test_switch (16, 0);
215 switch_val += switch_m;
228 || (ifelse_val1 != 31)
229 || (ifelse_val2 != 23)
230 || (ifelse_val3 != 246)
231 || (switch_val != 55))