[committed] Fix previously latent bug in reorg affecting cris port
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / memcpy-2.c
blob97d90ec987287d51c27f6feb4f599afa26024e9d
1 /* Copyright (C) 2002 Free Software Foundation.
3 Test memcpy with various combinations of pointer alignments and lengths to
4 make sure any optimizations in the library are correct.
6 Written by Michael Meissner, March 9, 2002. */
8 #include <string.h>
10 void abort (void);
11 void exit (int);
13 #ifndef MAX_OFFSET
14 #define MAX_OFFSET (sizeof (long long))
15 #endif
17 #ifndef MAX_COPY
18 #define MAX_COPY (10 * sizeof (long long))
19 #endif
21 #ifndef MAX_EXTRA
22 #define MAX_EXTRA (sizeof (long long))
23 #endif
25 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
28 /* Use a sequence length that is not divisible by two, to make it more
29 likely to detect when words are mixed up. */
30 #define SEQUENCE_LENGTH 31
32 static union {
33 char buf[MAX_LENGTH];
34 long long align_int;
35 long double align_fp;
36 } u1, u2;
38 int
39 main (void)
41 int off1, off2, len, i;
42 char *p, *q, c;
44 for (off1 = 0; off1 < MAX_OFFSET; off1++)
45 for (off2 = 0; off2 < MAX_OFFSET; off2++)
46 for (len = 1; len < MAX_COPY; len++)
48 for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
50 u1.buf[i] = 'a';
51 if (c >= 'A' + SEQUENCE_LENGTH)
52 c = 'A';
53 u2.buf[i] = c;
56 p = memcpy (u1.buf + off1, u2.buf + off2, len);
57 if (p != u1.buf + off1)
58 abort ();
60 q = u1.buf;
61 for (i = 0; i < off1; i++, q++)
62 if (*q != 'a')
63 abort ();
65 for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
67 if (c >= 'A' + SEQUENCE_LENGTH)
68 c = 'A';
69 if (*q != c)
70 abort ();
73 for (i = 0; i < MAX_EXTRA; i++, q++)
74 if (*q != 'a')
75 abort ();
78 exit (0);