struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-memset-2.c
blobc2dd34798f0649cbe6eb2764cd872d3bafd06a53
1 /*
2 memset-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 /* Copyright (C) 2002 Free Software Foundation.
9 Test memset with various combinations of pointer alignments and constant
10 lengths to make sure any optimizations in the compiler are correct.
12 Written by Roger Sayle, April 22, 2002. */
14 #ifndef MAX_OFFSET
15 #define MAX_OFFSET (sizeof (long long))
16 #endif
18 #ifndef MAX_COPY
19 #define MAX_COPY 15
20 #endif
22 #ifndef MAX_EXTRA
23 #define MAX_EXTRA (sizeof (long long))
24 #endif
26 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
28 #if 0 // TODO: Enable when SDCC supports long double!
29 static union {
30 char buf[MAX_LENGTH];
31 long long align_int;
32 long double align_fp;
33 } u;
35 char A = 'A';
37 void reset ()
39 int i;
41 for (i = 0; i < MAX_LENGTH; i++)
42 u.buf[i] = 'a';
45 void check (int off, int len, int ch)
47 char *q;
48 int i;
50 q = u.buf;
51 for (i = 0; i < off; i++, q++)
52 if (*q != 'a')
53 abort ();
55 for (i = 0; i < len; i++, q++)
56 if (*q != ch)
57 abort ();
59 for (i = 0; i < MAX_EXTRA; i++, q++)
60 if (*q != 'a')
61 abort ();
63 #endif
64 void
65 testTortureExecute (void)
67 #if 0
68 int off;
69 char *p;
71 /* len == 1 */
72 for (off = 0; off < MAX_OFFSET; off++)
74 reset ();
76 p = memset (u.buf + off, '\0', 1);
77 if (p != u.buf + off) abort ();
78 check (off, 1, '\0');
80 p = memset (u.buf + off, A, 1);
81 if (p != u.buf + off) abort ();
82 check (off, 1, 'A');
84 p = memset (u.buf + off, 'B', 1);
85 if (p != u.buf + off) abort ();
86 check (off, 1, 'B');
89 /* len == 2 */
90 for (off = 0; off < MAX_OFFSET; off++)
92 reset ();
94 p = memset (u.buf + off, '\0', 2);
95 if (p != u.buf + off) abort ();
96 check (off, 2, '\0');
98 p = memset (u.buf + off, A, 2);
99 if (p != u.buf + off) abort ();
100 check (off, 2, 'A');
102 p = memset (u.buf + off, 'B', 2);
103 if (p != u.buf + off) abort ();
104 check (off, 2, 'B');
107 /* len == 3 */
108 for (off = 0; off < MAX_OFFSET; off++)
110 reset ();
112 p = memset (u.buf + off, '\0', 3);
113 if (p != u.buf + off) abort ();
114 check (off, 3, '\0');
116 p = memset (u.buf + off, A, 3);
117 if (p != u.buf + off) abort ();
118 check (off, 3, 'A');
120 p = memset (u.buf + off, 'B', 3);
121 if (p != u.buf + off) abort ();
122 check (off, 3, 'B');
125 /* len == 4 */
126 for (off = 0; off < MAX_OFFSET; off++)
128 reset ();
130 p = memset (u.buf + off, '\0', 4);
131 if (p != u.buf + off) abort ();
132 check (off, 4, '\0');
134 p = memset (u.buf + off, A, 4);
135 if (p != u.buf + off) abort ();
136 check (off, 4, 'A');
138 p = memset (u.buf + off, 'B', 4);
139 if (p != u.buf + off) abort ();
140 check (off, 4, 'B');
143 /* len == 5 */
144 for (off = 0; off < MAX_OFFSET; off++)
146 reset ();
148 p = memset (u.buf + off, '\0', 5);
149 if (p != u.buf + off) abort ();
150 check (off, 5, '\0');
152 p = memset (u.buf + off, A, 5);
153 if (p != u.buf + off) abort ();
154 check (off, 5, 'A');
156 p = memset (u.buf + off, 'B', 5);
157 if (p != u.buf + off) abort ();
158 check (off, 5, 'B');
161 /* len == 6 */
162 for (off = 0; off < MAX_OFFSET; off++)
164 reset ();
166 p = memset (u.buf + off, '\0', 6);
167 if (p != u.buf + off) abort ();
168 check (off, 6, '\0');
170 p = memset (u.buf + off, A, 6);
171 if (p != u.buf + off) abort ();
172 check (off, 6, 'A');
174 p = memset (u.buf + off, 'B', 6);
175 if (p != u.buf + off) abort ();
176 check (off, 6, 'B');
179 /* len == 7 */
180 for (off = 0; off < MAX_OFFSET; off++)
182 reset ();
184 p = memset (u.buf + off, '\0', 7);
185 if (p != u.buf + off) abort ();
186 check (off, 7, '\0');
188 p = memset (u.buf + off, A, 7);
189 if (p != u.buf + off) abort ();
190 check (off, 7, 'A');
192 p = memset (u.buf + off, 'B', 7);
193 if (p != u.buf + off) abort ();
194 check (off, 7, 'B');
197 /* len == 8 */
198 for (off = 0; off < MAX_OFFSET; off++)
200 reset ();
202 p = memset (u.buf + off, '\0', 8);
203 if (p != u.buf + off) abort ();
204 check (off, 8, '\0');
206 p = memset (u.buf + off, A, 8);
207 if (p != u.buf + off) abort ();
208 check (off, 8, 'A');
210 p = memset (u.buf + off, 'B', 8);
211 if (p != u.buf + off) abort ();
212 check (off, 8, 'B');
215 /* len == 9 */
216 for (off = 0; off < MAX_OFFSET; off++)
218 reset ();
220 p = memset (u.buf + off, '\0', 9);
221 if (p != u.buf + off) abort ();
222 check (off, 9, '\0');
224 p = memset (u.buf + off, A, 9);
225 if (p != u.buf + off) abort ();
226 check (off, 9, 'A');
228 p = memset (u.buf + off, 'B', 9);
229 if (p != u.buf + off) abort ();
230 check (off, 9, 'B');
233 /* len == 10 */
234 for (off = 0; off < MAX_OFFSET; off++)
236 reset ();
238 p = memset (u.buf + off, '\0', 10);
239 if (p != u.buf + off) abort ();
240 check (off, 10, '\0');
242 p = memset (u.buf + off, A, 10);
243 if (p != u.buf + off) abort ();
244 check (off, 10, 'A');
246 p = memset (u.buf + off, 'B', 10);
247 if (p != u.buf + off) abort ();
248 check (off, 10, 'B');
251 /* len == 11 */
252 for (off = 0; off < MAX_OFFSET; off++)
254 reset ();
256 p = memset (u.buf + off, '\0', 11);
257 if (p != u.buf + off) abort ();
258 check (off, 11, '\0');
260 p = memset (u.buf + off, A, 11);
261 if (p != u.buf + off) abort ();
262 check (off, 11, 'A');
264 p = memset (u.buf + off, 'B', 11);
265 if (p != u.buf + off) abort ();
266 check (off, 11, 'B');
269 /* len == 12 */
270 for (off = 0; off < MAX_OFFSET; off++)
272 reset ();
274 p = memset (u.buf + off, '\0', 12);
275 if (p != u.buf + off) abort ();
276 check (off, 12, '\0');
278 p = memset (u.buf + off, A, 12);
279 if (p != u.buf + off) abort ();
280 check (off, 12, 'A');
282 p = memset (u.buf + off, 'B', 12);
283 if (p != u.buf + off) abort ();
284 check (off, 12, 'B');
287 /* len == 13 */
288 for (off = 0; off < MAX_OFFSET; off++)
290 reset ();
292 p = memset (u.buf + off, '\0', 13);
293 if (p != u.buf + off) abort ();
294 check (off, 13, '\0');
296 p = memset (u.buf + off, A, 13);
297 if (p != u.buf + off) abort ();
298 check (off, 13, 'A');
300 p = memset (u.buf + off, 'B', 13);
301 if (p != u.buf + off) abort ();
302 check (off, 13, 'B');
305 /* len == 14 */
306 for (off = 0; off < MAX_OFFSET; off++)
308 reset ();
310 p = memset (u.buf + off, '\0', 14);
311 if (p != u.buf + off) abort ();
312 check (off, 14, '\0');
314 p = memset (u.buf + off, A, 14);
315 if (p != u.buf + off) abort ();
316 check (off, 14, 'A');
318 p = memset (u.buf + off, 'B', 14);
319 if (p != u.buf + off) abort ();
320 check (off, 14, 'B');
323 /* len == 15 */
324 for (off = 0; off < MAX_OFFSET; off++)
326 reset ();
328 p = memset (u.buf + off, '\0', 15);
329 if (p != u.buf + off) abort ();
330 check (off, 15, '\0');
332 p = memset (u.buf + off, A, 15);
333 if (p != u.buf + off) abort ();
334 check (off, 15, 'A');
336 p = memset (u.buf + off, 'B', 15);
337 if (p != u.buf + off) abort ();
338 check (off, 15, 'B');
340 #endif
341 return;