OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [memset-2.c] - Blame information for rev 301

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 297 jeremybenn
/* Copyright (C) 2002  Free Software Foundation.
2
 
3
   Test memset with various combinations of pointer alignments and constant
4
   lengths to make sure any optimizations in the compiler are correct.
5
 
6
   Written by Roger Sayle, April 22, 2002.  */
7
 
8
#ifndef MAX_OFFSET
9
#define MAX_OFFSET (sizeof (long long))
10
#endif
11
 
12
#ifndef MAX_COPY
13
#define MAX_COPY 15
14
#endif
15
 
16
#ifndef MAX_EXTRA
17
#define MAX_EXTRA (sizeof (long long))
18
#endif
19
 
20
#define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
21
 
22
static union {
23
  char buf[MAX_LENGTH];
24
  long long align_int;
25
  long double align_fp;
26
} u;
27
 
28
char A = 'A';
29
 
30
void reset ()
31
{
32
  int i;
33
 
34
  for (i = 0; i < MAX_LENGTH; i++)
35
    u.buf[i] = 'a';
36
}
37
 
38
void check (int off, int len, int ch)
39
{
40
  char *q;
41
  int i;
42
 
43
  q = u.buf;
44
  for (i = 0; i < off; i++, q++)
45
    if (*q != 'a')
46
      abort ();
47
 
48
  for (i = 0; i < len; i++, q++)
49
    if (*q != ch)
50
      abort ();
51
 
52
  for (i = 0; i < MAX_EXTRA; i++, q++)
53
    if (*q != 'a')
54
      abort ();
55
}
56
 
57
int main ()
58
{
59
  int off;
60
  char *p;
61
 
62
  /* len == 1 */
63
  for (off = 0; off < MAX_OFFSET; off++)
64
    {
65
      reset ();
66
 
67
      p = memset (u.buf + off, '\0', 1);
68
      if (p != u.buf + off) abort ();
69
      check (off, 1, '\0');
70
 
71
      p = memset (u.buf + off, A, 1);
72
      if (p != u.buf + off) abort ();
73
      check (off, 1, 'A');
74
 
75
      p = memset (u.buf + off, 'B', 1);
76
      if (p != u.buf + off) abort ();
77
      check (off, 1, 'B');
78
    }
79
 
80
  /* len == 2 */
81
  for (off = 0; off < MAX_OFFSET; off++)
82
    {
83
      reset ();
84
 
85
      p = memset (u.buf + off, '\0', 2);
86
      if (p != u.buf + off) abort ();
87
      check (off, 2, '\0');
88
 
89
      p = memset (u.buf + off, A, 2);
90
      if (p != u.buf + off) abort ();
91
      check (off, 2, 'A');
92
 
93
      p = memset (u.buf + off, 'B', 2);
94
      if (p != u.buf + off) abort ();
95
      check (off, 2, 'B');
96
    }
97
 
98
  /* len == 3 */
99
  for (off = 0; off < MAX_OFFSET; off++)
100
    {
101
      reset ();
102
 
103
      p = memset (u.buf + off, '\0', 3);
104
      if (p != u.buf + off) abort ();
105
      check (off, 3, '\0');
106
 
107
      p = memset (u.buf + off, A, 3);
108
      if (p != u.buf + off) abort ();
109
      check (off, 3, 'A');
110
 
111
      p = memset (u.buf + off, 'B', 3);
112
      if (p != u.buf + off) abort ();
113
      check (off, 3, 'B');
114
    }
115
 
116
  /* len == 4 */
117
  for (off = 0; off < MAX_OFFSET; off++)
118
    {
119
      reset ();
120
 
121
      p = memset (u.buf + off, '\0', 4);
122
      if (p != u.buf + off) abort ();
123
      check (off, 4, '\0');
124
 
125
      p = memset (u.buf + off, A, 4);
126
      if (p != u.buf + off) abort ();
127
      check (off, 4, 'A');
128
 
129
      p = memset (u.buf + off, 'B', 4);
130
      if (p != u.buf + off) abort ();
131
      check (off, 4, 'B');
132
    }
133
 
134
  /* len == 5 */
135
  for (off = 0; off < MAX_OFFSET; off++)
136
    {
137
      reset ();
138
 
139
      p = memset (u.buf + off, '\0', 5);
140
      if (p != u.buf + off) abort ();
141
      check (off, 5, '\0');
142
 
143
      p = memset (u.buf + off, A, 5);
144
      if (p != u.buf + off) abort ();
145
      check (off, 5, 'A');
146
 
147
      p = memset (u.buf + off, 'B', 5);
148
      if (p != u.buf + off) abort ();
149
      check (off, 5, 'B');
150
    }
151
 
152
  /* len == 6 */
153
  for (off = 0; off < MAX_OFFSET; off++)
154
    {
155
      reset ();
156
 
157
      p = memset (u.buf + off, '\0', 6);
158
      if (p != u.buf + off) abort ();
159
      check (off, 6, '\0');
160
 
161
      p = memset (u.buf + off, A, 6);
162
      if (p != u.buf + off) abort ();
163
      check (off, 6, 'A');
164
 
165
      p = memset (u.buf + off, 'B', 6);
166
      if (p != u.buf + off) abort ();
167
      check (off, 6, 'B');
168
    }
169
 
170
  /* len == 7 */
171
  for (off = 0; off < MAX_OFFSET; off++)
172
    {
173
      reset ();
174
 
175
      p = memset (u.buf + off, '\0', 7);
176
      if (p != u.buf + off) abort ();
177
      check (off, 7, '\0');
178
 
179
      p = memset (u.buf + off, A, 7);
180
      if (p != u.buf + off) abort ();
181
      check (off, 7, 'A');
182
 
183
      p = memset (u.buf + off, 'B', 7);
184
      if (p != u.buf + off) abort ();
185
      check (off, 7, 'B');
186
    }
187
 
188
  /* len == 8 */
189
  for (off = 0; off < MAX_OFFSET; off++)
190
    {
191
      reset ();
192
 
193
      p = memset (u.buf + off, '\0', 8);
194
      if (p != u.buf + off) abort ();
195
      check (off, 8, '\0');
196
 
197
      p = memset (u.buf + off, A, 8);
198
      if (p != u.buf + off) abort ();
199
      check (off, 8, 'A');
200
 
201
      p = memset (u.buf + off, 'B', 8);
202
      if (p != u.buf + off) abort ();
203
      check (off, 8, 'B');
204
    }
205
 
206
  /* len == 9 */
207
  for (off = 0; off < MAX_OFFSET; off++)
208
    {
209
      reset ();
210
 
211
      p = memset (u.buf + off, '\0', 9);
212
      if (p != u.buf + off) abort ();
213
      check (off, 9, '\0');
214
 
215
      p = memset (u.buf + off, A, 9);
216
      if (p != u.buf + off) abort ();
217
      check (off, 9, 'A');
218
 
219
      p = memset (u.buf + off, 'B', 9);
220
      if (p != u.buf + off) abort ();
221
      check (off, 9, 'B');
222
    }
223
 
224
  /* len == 10 */
225
  for (off = 0; off < MAX_OFFSET; off++)
226
    {
227
      reset ();
228
 
229
      p = memset (u.buf + off, '\0', 10);
230
      if (p != u.buf + off) abort ();
231
      check (off, 10, '\0');
232
 
233
      p = memset (u.buf + off, A, 10);
234
      if (p != u.buf + off) abort ();
235
      check (off, 10, 'A');
236
 
237
      p = memset (u.buf + off, 'B', 10);
238
      if (p != u.buf + off) abort ();
239
      check (off, 10, 'B');
240
    }
241
 
242
  /* len == 11 */
243
  for (off = 0; off < MAX_OFFSET; off++)
244
    {
245
      reset ();
246
 
247
      p = memset (u.buf + off, '\0', 11);
248
      if (p != u.buf + off) abort ();
249
      check (off, 11, '\0');
250
 
251
      p = memset (u.buf + off, A, 11);
252
      if (p != u.buf + off) abort ();
253
      check (off, 11, 'A');
254
 
255
      p = memset (u.buf + off, 'B', 11);
256
      if (p != u.buf + off) abort ();
257
      check (off, 11, 'B');
258
    }
259
 
260
  /* len == 12 */
261
  for (off = 0; off < MAX_OFFSET; off++)
262
    {
263
      reset ();
264
 
265
      p = memset (u.buf + off, '\0', 12);
266
      if (p != u.buf + off) abort ();
267
      check (off, 12, '\0');
268
 
269
      p = memset (u.buf + off, A, 12);
270
      if (p != u.buf + off) abort ();
271
      check (off, 12, 'A');
272
 
273
      p = memset (u.buf + off, 'B', 12);
274
      if (p != u.buf + off) abort ();
275
      check (off, 12, 'B');
276
    }
277
 
278
  /* len == 13 */
279
  for (off = 0; off < MAX_OFFSET; off++)
280
    {
281
      reset ();
282
 
283
      p = memset (u.buf + off, '\0', 13);
284
      if (p != u.buf + off) abort ();
285
      check (off, 13, '\0');
286
 
287
      p = memset (u.buf + off, A, 13);
288
      if (p != u.buf + off) abort ();
289
      check (off, 13, 'A');
290
 
291
      p = memset (u.buf + off, 'B', 13);
292
      if (p != u.buf + off) abort ();
293
      check (off, 13, 'B');
294
    }
295
 
296
  /* len == 14 */
297
  for (off = 0; off < MAX_OFFSET; off++)
298
    {
299
      reset ();
300
 
301
      p = memset (u.buf + off, '\0', 14);
302
      if (p != u.buf + off) abort ();
303
      check (off, 14, '\0');
304
 
305
      p = memset (u.buf + off, A, 14);
306
      if (p != u.buf + off) abort ();
307
      check (off, 14, 'A');
308
 
309
      p = memset (u.buf + off, 'B', 14);
310
      if (p != u.buf + off) abort ();
311
      check (off, 14, 'B');
312
    }
313
 
314
  /* len == 15 */
315
  for (off = 0; off < MAX_OFFSET; off++)
316
    {
317
      reset ();
318
 
319
      p = memset (u.buf + off, '\0', 15);
320
      if (p != u.buf + off) abort ();
321
      check (off, 15, '\0');
322
 
323
      p = memset (u.buf + off, A, 15);
324
      if (p != u.buf + off) abort ();
325
      check (off, 15, 'A');
326
 
327
      p = memset (u.buf + off, 'B', 15);
328
      if (p != u.buf + off) abort ();
329
      check (off, 15, 'B');
330
    }
331
 
332
  exit (0);
333
}
334
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.