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