PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / memcpy-2.c
blobf328b64778d9af8b27cfd76586e5377da0511f01
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 #ifndef MAX_OFFSET
11 #define MAX_OFFSET (sizeof (long long))
12 #endif
14 #ifndef MAX_COPY
15 #define MAX_COPY (10 * sizeof (long long))
16 #endif
18 #ifndef MAX_EXTRA
19 #define MAX_EXTRA (sizeof (long long))
20 #endif
22 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
25 /* Use a sequence length that is not divisible by two, to make it more
26 likely to detect when words are mixed up. */
27 #define SEQUENCE_LENGTH 31
29 static union {
30 char buf[MAX_LENGTH];
31 long long align_int;
32 long double align_fp;
33 } u1, u2;
35 main ()
37 int off1, off2, len, i;
38 char *p, *q, c;
40 for (off1 = 0; off1 < MAX_OFFSET; off1++)
41 for (off2 = 0; off2 < MAX_OFFSET; off2++)
42 for (len = 1; len < MAX_COPY; len++)
44 for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
46 u1.buf[i] = 'a';
47 if (c >= 'A' + SEQUENCE_LENGTH)
48 c = 'A';
49 u2.buf[i] = c;
52 p = memcpy (u1.buf + off1, u2.buf + off2, len);
53 if (p != u1.buf + off1)
54 abort ();
56 q = u1.buf;
57 for (i = 0; i < off1; i++, q++)
58 if (*q != 'a')
59 abort ();
61 for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
63 if (c >= 'A' + SEQUENCE_LENGTH)
64 c = 'A';
65 if (*q != c)
66 abort ();
69 for (i = 0; i < MAX_EXTRA; i++, q++)
70 if (*q != 'a')
71 abort ();
74 exit (0);