RISC-V: Implement TARGET_CAN_INLINE_P
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / strcpy-1.c
blobffa27c54ca8c3d640b8595faad795a42c902b16e
1 /* Copyright (C) 2002 Free Software Foundation.
3 Test strcpy with various combinations of pointer alignments and lengths to
4 make sure any optimizations in the library are correct. */
6 #include <string.h>
8 void abort (void);
9 void exit (int);
11 #ifndef MAX_OFFSET
12 #define MAX_OFFSET (sizeof (long long))
13 #endif
15 #ifndef MAX_COPY
16 #define MAX_COPY (10 * sizeof (long long))
17 #endif
19 #ifndef MAX_EXTRA
20 #define MAX_EXTRA (sizeof (long long))
21 #endif
23 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + 1 + 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 int
36 main (void)
38 int off1, off2, len, i;
39 char *p, *q, c;
41 for (off1 = 0; off1 < MAX_OFFSET; off1++)
42 for (off2 = 0; off2 < MAX_OFFSET; off2++)
43 for (len = 1; len < MAX_COPY; len++)
45 for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
47 u1.buf[i] = 'a';
48 if (c >= 'A' + SEQUENCE_LENGTH)
49 c = 'A';
50 u2.buf[i] = c;
52 u2.buf[off2 + len] = '\0';
54 p = strcpy (u1.buf + off1, u2.buf + off2);
55 if (p != u1.buf + off1)
56 abort ();
58 q = u1.buf;
59 for (i = 0; i < off1; i++, q++)
60 if (*q != 'a')
61 abort ();
63 for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
65 if (c >= 'A' + SEQUENCE_LENGTH)
66 c = 'A';
67 if (*q != c)
68 abort ();
71 if (*q++ != '\0')
72 abort ();
73 for (i = 0; i < MAX_EXTRA; i++, q++)
74 if (*q != 'a')
75 abort ();
78 exit (0);