Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/memset-1.c

raw
1 /* Copyright (C) 2002 Free Software Foundation.
2
3 Test memset with various combinations of pointer alignments and lengths to
4 make sure any optimizations in the library are correct.
5
6 Written by Michael Meissner, March 9, 2002. */
7
8 #include <string.h>
9
10 void abort (void);
11 void exit (int);
12
13 #ifndef MAX_OFFSET
14 #define MAX_OFFSET (sizeof (long long))
15 #endif
16
17 #ifndef MAX_COPY
18 #define MAX_COPY (10 * sizeof (long long))
19 #endif
20
21 #ifndef MAX_EXTRA
22 #define MAX_EXTRA (sizeof (long long))
23 #endif
24
25 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
26
27 static union {
28 char buf[MAX_LENGTH];
29 long long align_int;
30 long double align_fp;
31 } u;
32
33 char A = 'A';
34
35 int
36 main (void)
37 {
38 int off, len, i;
39 char *p, *q;
40
41 for (off = 0; off < MAX_OFFSET; off++)
42 for (len = 1; len < MAX_COPY; len++)
43 {
44 for (i = 0; i < MAX_LENGTH; i++)
45 u.buf[i] = 'a';
46
47 p = memset (u.buf + off, '\0', len);
48 if (p != u.buf + off)
49 abort ();
50
51 q = u.buf;
52 for (i = 0; i < off; i++, q++)
53 if (*q != 'a')
54 abort ();
55
56 for (i = 0; i < len; i++, q++)
57 if (*q != '\0')
58 abort ();
59
60 for (i = 0; i < MAX_EXTRA; i++, q++)
61 if (*q != 'a')
62 abort ();
63
64 p = memset (u.buf + off, A, len);
65 if (p != u.buf + off)
66 abort ();
67
68 q = u.buf;
69 for (i = 0; i < off; i++, q++)
70 if (*q != 'a')
71 abort ();
72
73 for (i = 0; i < len; i++, q++)
74 if (*q != 'A')
75 abort ();
76
77 for (i = 0; i < MAX_EXTRA; i++, q++)
78 if (*q != 'a')
79 abort ();
80
81 p = memset (u.buf + off, 'B', len);
82 if (p != u.buf + off)
83 abort ();
84
85 q = u.buf;
86 for (i = 0; i < off; i++, q++)
87 if (*q != 'a')
88 abort ();
89
90 for (i = 0; i < len; i++, q++)
91 if (*q != 'B')
92 abort ();
93
94 for (i = 0; i < MAX_EXTRA; i++, q++)
95 if (*q != 'a')
96 abort ();
97 }
98
99 exit (0);
100 }