struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-memset-3.c
blob642b8ba988f36014a7d964c9c22250abf607b3ce
1 /*
2 memset-3.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #include <string.h>
9 /* Copyright (C) 2002 Free Software Foundation.
11 Test memset with various combinations of constant pointer alignments and
12 lengths to make sure any optimizations in the compiler are correct.
14 Written by Roger Sayle, July 22, 2002. */
16 #ifndef MAX_OFFSET
17 #define MAX_OFFSET (sizeof (long long))
18 #endif
20 #ifndef MAX_COPY
21 #define MAX_COPY 15
22 #endif
24 #ifndef MAX_EXTRA
25 #define MAX_EXTRA (sizeof (long long))
26 #endif
28 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
30 #if 0 // TODO: Enable when SDC supports long double!
31 static union {
32 char buf[MAX_LENGTH];
33 long long align_int;
34 long double align_fp;
35 } u;
37 char A = 'A';
39 void reset ()
41 int i;
43 for (i = 0; i < MAX_LENGTH; i++)
44 u.buf[i] = 'a';
47 void check (int off, int len, int ch)
49 char *q;
50 int i;
52 q = u.buf;
53 for (i = 0; i < off; i++, q++)
54 if (*q != 'a')
55 ASSERT (0);
57 for (i = 0; i < len; i++, q++)
58 if (*q != ch)
59 ASSERT (0);
61 for (i = 0; i < MAX_EXTRA; i++, q++)
62 if (*q != 'a')
63 ASSERT (0);
65 #endif
66 void
67 testTortureExecute (void)
69 #if 0
70 int len;
71 char *p;
73 /* off == 0 */
74 for (len = 0; len < MAX_COPY; len++)
76 reset ();
78 p = memset (u.buf, '\0', len);
79 if (p != u.buf) ASSERT (0);
80 check (0, len, '\0');
82 p = memset (u.buf, A, len);
83 if (p != u.buf) ASSERT (0);
84 check (0, len, 'A');
86 p = memset (u.buf, 'B', len);
87 if (p != u.buf) ASSERT (0);
88 check (0, len, 'B');
91 /* off == 1 */
92 for (len = 0; len < MAX_COPY; len++)
94 reset ();
96 p = memset (u.buf+1, '\0', len);
97 if (p != u.buf+1) ASSERT (0);
98 check (1, len, '\0');
100 p = memset (u.buf+1, A, len);
101 if (p != u.buf+1) ASSERT (0);
102 check (1, len, 'A');
104 p = memset (u.buf+1, 'B', len);
105 if (p != u.buf+1) ASSERT (0);
106 check (1, len, 'B');
109 /* off == 2 */
110 for (len = 0; len < MAX_COPY; len++)
112 reset ();
114 p = memset (u.buf+2, '\0', len);
115 if (p != u.buf+2) ASSERT (0);
116 check (2, len, '\0');
118 p = memset (u.buf+2, A, len);
119 if (p != u.buf+2) ASSERT (0);
120 check (2, len, 'A');
122 p = memset (u.buf+2, 'B', len);
123 if (p != u.buf+2) ASSERT (0);
124 check (2, len, 'B');
127 /* off == 3 */
128 for (len = 0; len < MAX_COPY; len++)
130 reset ();
132 p = memset (u.buf+3, '\0', len);
133 if (p != u.buf+3) ASSERT (0);
134 check (3, len, '\0');
136 p = memset (u.buf+3, A, len);
137 if (p != u.buf+3) ASSERT (0);
138 check (3, len, 'A');
140 p = memset (u.buf+3, 'B', len);
141 if (p != u.buf+3) ASSERT (0);
142 check (3, len, 'B');
145 /* off == 4 */
146 for (len = 0; len < MAX_COPY; len++)
148 reset ();
150 p = memset (u.buf+4, '\0', len);
151 if (p != u.buf+4) ASSERT (0);
152 check (4, len, '\0');
154 p = memset (u.buf+4, A, len);
155 if (p != u.buf+4) ASSERT (0);
156 check (4, len, 'A');
158 p = memset (u.buf+4, 'B', len);
159 if (p != u.buf+4) ASSERT (0);
160 check (4, len, 'B');
163 /* off == 5 */
164 for (len = 0; len < MAX_COPY; len++)
166 reset ();
168 p = memset (u.buf+5, '\0', len);
169 if (p != u.buf+5) ASSERT (0);
170 check (5, len, '\0');
172 p = memset (u.buf+5, A, len);
173 if (p != u.buf+5) ASSERT (0);
174 check (5, len, 'A');
176 p = memset (u.buf+5, 'B', len);
177 if (p != u.buf+5) ASSERT (0);
178 check (5, len, 'B');
181 /* off == 6 */
182 for (len = 0; len < MAX_COPY; len++)
184 reset ();
186 p = memset (u.buf+6, '\0', len);
187 if (p != u.buf+6) ASSERT (0);
188 check (6, len, '\0');
190 p = memset (u.buf+6, A, len);
191 if (p != u.buf+6) ASSERT (0);
192 check (6, len, 'A');
194 p = memset (u.buf+6, 'B', len);
195 if (p != u.buf+6) ASSERT (0);
196 check (6, len, 'B');
199 /* off == 7 */
200 for (len = 0; len < MAX_COPY; len++)
202 reset ();
204 p = memset (u.buf+7, '\0', len);
205 if (p != u.buf+7) ASSERT (0);
206 check (7, len, '\0');
208 p = memset (u.buf+7, A, len);
209 if (p != u.buf+7) ASSERT (0);
210 check (7, len, 'A');
212 p = memset (u.buf+7, 'B', len);
213 if (p != u.buf+7) ASSERT (0);
214 check (7, len, 'B');
216 #endif
217 return;