struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strcpy-1.c
blobc44770d6105fa862f13295b2a4aca65bb4f140bd
1 /*
2 strcpy-1.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 /* Copyright (C) 2002 Free Software Foundation.
9 Test strcpy with various combinations of pointer alignments and lengths to
10 make sure any optimizations in the library are correct. */
12 #include <string.h>
14 #ifndef MAX_OFFSET
15 #define MAX_OFFSET (sizeof (long long))
16 #endif
18 #ifndef MAX_COPY
19 #define MAX_COPY (3 * sizeof (long long)) /* Was (10 * sizeof (long long)) in GCC, reduced to speed up regression testing */
20 #endif
22 #ifndef MAX_EXTRA
23 #define MAX_EXTRA (sizeof (long long))
24 #endif
26 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + 1 + 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 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
33 static union {
34 char buf[MAX_LENGTH];
35 long long align_int;
36 #if 0 // TODO: Emable when SDCC suports long double!
37 long double align_fp;
38 #endif
39 } u1, u2;
40 #endif
42 void
43 testTortureExecute (void)
45 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
46 int off1, off2, len, i;
47 char *p, *q, c;
49 for (off1 = 0; off1 < MAX_OFFSET; off1++)
50 for (off2 = 0; off2 < MAX_OFFSET; off2++)
51 for (len = 1; len < MAX_COPY; len++)
53 for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
55 u1.buf[i] = 'a';
56 if (c >= 'A' + SEQUENCE_LENGTH)
57 c = 'A';
58 u2.buf[i] = c;
60 u2.buf[off2 + len] = '\0';
62 p = strcpy (u1.buf + off1, u2.buf + off2);
63 if (p != u1.buf + off1)
64 ASSERT (0);
66 q = u1.buf;
67 for (i = 0; i < off1; i++, q++)
68 if (*q != 'a')
69 ASSERT (0);
71 for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
73 if (c >= 'A' + SEQUENCE_LENGTH)
74 c = 'A';
75 if (*q != c)
76 ASSERT (0);
79 if (*q++ != '\0')
80 ASSERT (0);
81 for (i = 0; i < MAX_EXTRA; i++, q++)
82 if (*q != 'a')
83 ASSERT (0);
85 #endif
86 return;