Debian Codegraph @

gcc/testsuite/gdc.test/runnable/loopunroll.d

raw
1 /*
2 PERMUTE_ARGS: -O
3 RUN_OUTPUT:
4 ---
5 0
6 45
7 45
8 45
9 45
10 45
11 45
12 45
13 10
14 45
15 0
16 5
17 45
18 45
19 ---
20 */
21
22 import core.stdc.stdio;
23
24 version (all)
25 {
26
27 /************************************/
28
29 int func1(int[] data)
30 {
31 int j;
32 for (int i = 0; i < 10; i++) {
33 data[i*10] = i;
34 j = data[0] * 10;
35 }
36 return j;
37 }
38
39 void test1()
40 {
41 int[100] data = [1,7,6,3,8,9,7,2,2,4,
42 1,7,6,3,8,9,7,2,2,4,
43 1,7,6,3,8,9,7,2,2,4,
44 1,7,6,3,8,9,7,2,2,4,
45 1,7,6,3,8,9,7,2,2,4,
46 1,7,6,3,8,9,7,2,2,4,
47 1,7,6,3,8,9,7,2,2,4,
48 1,7,6,3,8,9,7,2,2,4,
49 1,7,6,3,8,9,7,2,2,4,
50 1,7,6,3,8,9,7,2,2,4,
51 ];
52 int i = func1(data[]);
53 if (i != 0)
54 assert(0);
55 printf("%d\n", i);
56 }
57
58 /************************************/
59
60 void test2()
61 {
62 int result = 0;
63 for (int i = 0; i < 10; ++i)
64 result += i;
65 printf("%d\n", result);
66 if (result != 45)
67 assert(0);
68 }
69
70 /************************************/
71
72 void test3()
73 {
74 int result = 0;
75 for (int i = 0; i < 10; i++)
76 result += i;
77 printf("%d\n", result);
78 if (result != 45)
79 assert(0);
80 }
81
82 /************************************/
83
84 void test4()
85 {
86 int result = 0;
87 for (int i = 0; i < 10; i += 1)
88 result += i;
89 printf("%d\n", result);
90 if (result != 45)
91 assert(0);
92 }
93
94 /************************************/
95
96 void test5()
97 {
98 int result = 0;
99 for (int i = 0; i < 10; i -= -1)
100 result += i;
101 printf("%d\n", result);
102 if (result != 45)
103 assert(0);
104 }
105
106 /************************************/
107
108 void test6()
109 {
110 int result = 0;
111 for (uint i = 0; i < 10; i++)
112 result += i;
113 printf("%d\n", result);
114 if (result != 45)
115 assert(0);
116 }
117
118 /************************************/
119
120 void test7()
121 {
122 int result = 0;
123 for (long i = 0; i < 10; i++)
124 result += i;
125 printf("%d\n", result);
126 if (result != 45)
127 assert(0);
128 }
129
130 /************************************/
131
132 void test8()
133 {
134 int result = 0;
135 for (ulong i = 0; i < 10; i++)
136 result += i;
137 printf("%d\n", result);
138 if (result != 45)
139 assert(0);
140 }
141
142 /************************************/
143
144 void test9()
145 {
146 int result = 0;
147 for (ulong i = 0; i < 5; i++)
148 result += i;
149 printf("%d\n", result);
150 if (result != 10)
151 assert(0);
152 }
153
154 /************************************/
155
156 void test10()
157 {
158 __gshared int i;
159 int result = 0;
160 for (i = 0; i < 10; i++)
161 result += i;
162 printf("%d\n", result);
163 if (result != 45)
164 assert(0);
165 }
166
167 /************************************/
168
169 void test11()
170 {
171 int result = 0;
172 for (int i = 0; i < 10; i += 10)
173 result += i;
174 printf("%d\n", result);
175 if (result != 0)
176 assert(0);
177 }
178
179 /************************************/
180
181 void test12()
182 {
183 int result = 0;
184 for (int i = 0; i < 10; i += 5)
185 result += i;
186 printf("%d\n", result);
187 if (result != 5)
188 assert(0);
189 }
190
191 /************************************/
192
193 void test13()
194 {
195 int result = 0;
196 int i;
197 int* p = &i;
198
199 int foo() { return *p; }
200
201 for (i = 0; i < 10; ++i)
202 {
203 if (foo() != i)
204 assert(0);
205 result += i;
206 }
207 printf("%d\n", result);
208 if (result != 45)
209 assert(0);
210 }
211
212 /************************************/
213
214 void test14()
215 {
216 int result = 0;
217 int i;
218
219 int foo() { return i; }
220
221 for (i = 0; i < 10; ++i)
222 {
223 if (foo() != i)
224 assert(0);
225 result += i;
226 }
227 printf("%d\n", result);
228 if (result != 45)
229 assert(0);
230 }
231
232 /************************************/
233
234 void test15()
235 {
236 int result = 0;
237 int i;
238
239 try
240 {
241 for (i = 0; i < 10; ++i)
242 {
243 if (i == 1)
244 throw new Exception("hello");
245 result += i;
246 }
247 assert(0);
248 }
249 catch (Exception e)
250 {
251 assert(i == 1);
252 }
253 }
254
255 /************************************/
256
257 int main()
258 {
259 test1();
260 test2();
261 test3();
262 test4();
263 test5();
264 test6();
265 test7();
266 test8();
267 test9();
268 test10();
269 test11();
270 test12();
271 test13();
272 test14();
273 test15();
274 return 0;
275 }
276
277 }
278 else
279 {
280
281 void main()
282 {
283 int result = 0;
284 int i;
285
286 try
287 {
288 for (i = 0; i < 10; ++i)
289 {
290 if (i == 1)
291 throw new Exception("hello");
292 result += i;
293 }
294 assert(0);
295 }
296 catch (Exception e)
297 {
298 assert(i == 1);
299 }
300 }
301
302 }