struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-memset-1.c
blob8dd6502bb65ceddc93a35dcc4d85bf4d4059a816
1 /*
2 memset-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 memset with various combinations of pointer alignments and lengths to
10 make sure any optimizations in the library are correct.
12 Written by Michael Meissner, March 9, 2002. */
14 #include <string.h>
16 #ifndef MAX_OFFSET
17 #define MAX_OFFSET (sizeof (long long))
18 #endif
20 #ifndef MAX_COPY
21 #define MAX_COPY (10 * sizeof (long long))
22 #endif
24 #ifndef MAX_EXTRA
25 #define MAX_EXTRA (sizeof (long long))
26 #endif
28 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
30 #if 0 // TODO: Enable when SDCC supports long double!
31 static union {
32 char buf[MAX_LENGTH];
33 long long align_int;
34 long double align_fp;
35 } u;
36 #endif
37 char A = 'A';
39 void
40 testTortureExecute (void)
42 #if 0
43 int off, len, i;
44 char *p, *q;
46 for (off = 0; off < MAX_OFFSET; off++)
47 for (len = 1; len < MAX_COPY; len++)
49 for (i = 0; i < MAX_LENGTH; i++)
50 u.buf[i] = 'a';
52 p = memset (u.buf + off, '\0', len);
53 if (p != u.buf + off)
54 abort ();
56 q = u.buf;
57 for (i = 0; i < off; i++, q++)
58 if (*q != 'a')
59 abort ();
61 for (i = 0; i < len; i++, q++)
62 if (*q != '\0')
63 abort ();
65 for (i = 0; i < MAX_EXTRA; i++, q++)
66 if (*q != 'a')
67 abort ();
69 p = memset (u.buf + off, A, len);
70 if (p != u.buf + off)
71 abort ();
73 q = u.buf;
74 for (i = 0; i < off; i++, q++)
75 if (*q != 'a')
76 abort ();
78 for (i = 0; i < len; i++, q++)
79 if (*q != 'A')
80 abort ();
82 for (i = 0; i < MAX_EXTRA; i++, q++)
83 if (*q != 'a')
84 abort ();
86 p = memset (u.buf + off, 'B', len);
87 if (p != u.buf + off)
88 abort ();
90 q = u.buf;
91 for (i = 0; i < off; i++, q++)
92 if (*q != 'a')
93 abort ();
95 for (i = 0; i < len; i++, q++)
96 if (*q != 'B')
97 abort ();
99 for (i = 0; i < MAX_EXTRA; i++, q++)
100 if (*q != 'a')
101 abort ();
103 #endif
104 return;