2 memset-2.c from the execute part of the gcc torture tests.
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. */
15 #define MAX_OFFSET (sizeof (long long))
23 #define MAX_EXTRA (sizeof (long long))
26 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
28 #if 0 // TODO: Enable when SDCC supports long double!
41 for (i
= 0; i
< MAX_LENGTH
; i
++)
45 void check (int off
, int len
, int ch
)
51 for (i
= 0; i
< off
; i
++, q
++)
55 for (i
= 0; i
< len
; i
++, q
++)
59 for (i
= 0; i
< MAX_EXTRA
; i
++, q
++)
65 testTortureExecute (void)
72 for (off
= 0; off
< MAX_OFFSET
; off
++)
76 p
= memset (u
.buf
+ off
, '\0', 1);
77 if (p
!= u
.buf
+ off
) abort ();
80 p
= memset (u
.buf
+ off
, A
, 1);
81 if (p
!= u
.buf
+ off
) abort ();
84 p
= memset (u
.buf
+ off
, 'B', 1);
85 if (p
!= u
.buf
+ off
) abort ();
90 for (off
= 0; off
< MAX_OFFSET
; off
++)
94 p
= memset (u
.buf
+ off
, '\0', 2);
95 if (p
!= u
.buf
+ off
) abort ();
98 p
= memset (u
.buf
+ off
, A
, 2);
99 if (p
!= u
.buf
+ off
) abort ();
102 p
= memset (u
.buf
+ off
, 'B', 2);
103 if (p
!= u
.buf
+ off
) abort ();
108 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
120 p
= memset (u
.buf
+ off
, 'B', 3);
121 if (p
!= u
.buf
+ off
) abort ();
126 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
138 p
= memset (u
.buf
+ off
, 'B', 4);
139 if (p
!= u
.buf
+ off
) abort ();
144 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
156 p
= memset (u
.buf
+ off
, 'B', 5);
157 if (p
!= u
.buf
+ off
) abort ();
162 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
174 p
= memset (u
.buf
+ off
, 'B', 6);
175 if (p
!= u
.buf
+ off
) abort ();
180 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
192 p
= memset (u
.buf
+ off
, 'B', 7);
193 if (p
!= u
.buf
+ off
) abort ();
198 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
210 p
= memset (u
.buf
+ off
, 'B', 8);
211 if (p
!= u
.buf
+ off
) abort ();
216 for (off
= 0; off
< MAX_OFFSET
; off
++)
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 ();
228 p
= memset (u
.buf
+ off
, 'B', 9);
229 if (p
!= u
.buf
+ off
) abort ();
234 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');
252 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');
270 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');
288 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');
306 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');
324 for (off
= 0; off
< MAX_OFFSET
; off
++)
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');