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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [memset-3.c] - Blame information for rev 801

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

Line No. Rev Author Line
1 688 jeremybenn
/* Copyright (C) 2002  Free Software Foundation.
2
 
3
   Test memset with various combinations of constant pointer alignments and
4
   lengths to make sure any optimizations in the compiler are correct.
5
 
6
   Written by Roger Sayle, July 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 len;
60
  char *p;
61
 
62
  /* off == 0 */
63
  for (len = 0; len < MAX_COPY; len++)
64
    {
65
      reset ();
66
 
67
      p = memset (u.buf, '\0', len);
68
      if (p != u.buf) abort ();
69
      check (0, len, '\0');
70
 
71
      p = memset (u.buf, A, len);
72
      if (p != u.buf) abort ();
73
      check (0, len, 'A');
74
 
75
      p = memset (u.buf, 'B', len);
76
      if (p != u.buf) abort ();
77
      check (0, len, 'B');
78
    }
79
 
80
  /* off == 1 */
81
  for (len = 0; len < MAX_COPY; len++)
82
    {
83
      reset ();
84
 
85
      p = memset (u.buf+1, '\0', len);
86
      if (p != u.buf+1) abort ();
87
      check (1, len, '\0');
88
 
89
      p = memset (u.buf+1, A, len);
90
      if (p != u.buf+1) abort ();
91
      check (1, len, 'A');
92
 
93
      p = memset (u.buf+1, 'B', len);
94
      if (p != u.buf+1) abort ();
95
      check (1, len, 'B');
96
    }
97
 
98
  /* off == 2 */
99
  for (len = 0; len < MAX_COPY; len++)
100
    {
101
      reset ();
102
 
103
      p = memset (u.buf+2, '\0', len);
104
      if (p != u.buf+2) abort ();
105
      check (2, len, '\0');
106
 
107
      p = memset (u.buf+2, A, len);
108
      if (p != u.buf+2) abort ();
109
      check (2, len, 'A');
110
 
111
      p = memset (u.buf+2, 'B', len);
112
      if (p != u.buf+2) abort ();
113
      check (2, len, 'B');
114
    }
115
 
116
  /* off == 3 */
117
  for (len = 0; len < MAX_COPY; len++)
118
    {
119
      reset ();
120
 
121
      p = memset (u.buf+3, '\0', len);
122
      if (p != u.buf+3) abort ();
123
      check (3, len, '\0');
124
 
125
      p = memset (u.buf+3, A, len);
126
      if (p != u.buf+3) abort ();
127
      check (3, len, 'A');
128
 
129
      p = memset (u.buf+3, 'B', len);
130
      if (p != u.buf+3) abort ();
131
      check (3, len, 'B');
132
    }
133
 
134
  /* off == 4 */
135
  for (len = 0; len < MAX_COPY; len++)
136
    {
137
      reset ();
138
 
139
      p = memset (u.buf+4, '\0', len);
140
      if (p != u.buf+4) abort ();
141
      check (4, len, '\0');
142
 
143
      p = memset (u.buf+4, A, len);
144
      if (p != u.buf+4) abort ();
145
      check (4, len, 'A');
146
 
147
      p = memset (u.buf+4, 'B', len);
148
      if (p != u.buf+4) abort ();
149
      check (4, len, 'B');
150
    }
151
 
152
  /* off == 5 */
153
  for (len = 0; len < MAX_COPY; len++)
154
    {
155
      reset ();
156
 
157
      p = memset (u.buf+5, '\0', len);
158
      if (p != u.buf+5) abort ();
159
      check (5, len, '\0');
160
 
161
      p = memset (u.buf+5, A, len);
162
      if (p != u.buf+5) abort ();
163
      check (5, len, 'A');
164
 
165
      p = memset (u.buf+5, 'B', len);
166
      if (p != u.buf+5) abort ();
167
      check (5, len, 'B');
168
    }
169
 
170
  /* off == 6 */
171
  for (len = 0; len < MAX_COPY; len++)
172
    {
173
      reset ();
174
 
175
      p = memset (u.buf+6, '\0', len);
176
      if (p != u.buf+6) abort ();
177
      check (6, len, '\0');
178
 
179
      p = memset (u.buf+6, A, len);
180
      if (p != u.buf+6) abort ();
181
      check (6, len, 'A');
182
 
183
      p = memset (u.buf+6, 'B', len);
184
      if (p != u.buf+6) abort ();
185
      check (6, len, 'B');
186
    }
187
 
188
  /* off == 7 */
189
  for (len = 0; len < MAX_COPY; len++)
190
    {
191
      reset ();
192
 
193
      p = memset (u.buf+7, '\0', len);
194
      if (p != u.buf+7) abort ();
195
      check (7, len, '\0');
196
 
197
      p = memset (u.buf+7, A, len);
198
      if (p != u.buf+7) abort ();
199
      check (7, len, 'A');
200
 
201
      p = memset (u.buf+7, 'B', len);
202
      if (p != u.buf+7) abort ();
203
      check (7, len, 'B');
204
    }
205
 
206
  exit (0);
207
}
208
 

powered by: WebSVN 2.1.0

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