struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strcmp-1.c
blobb0bcb9b2df72a2b5bc24687a6cb1aaa44da32f54
1 /*
2 strcmp-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 strcmp 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>
15 #include <stddef.h>
17 #ifndef MAX_OFFSET
18 #define MAX_OFFSET (sizeof (long long))
19 #endif
21 #ifndef MAX_TEST
22 #define MAX_TEST (2 * sizeof (long long)) /* Was (8 * sizeof (long long)) in GCC, reduced to speed up regression testing */
23 #endif
25 #ifndef MAX_EXTRA
26 #define MAX_EXTRA (sizeof (long long))
27 #endif
29 #define MAX_LENGTH (MAX_OFFSET + MAX_TEST + MAX_EXTRA + 2)
31 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
32 static union {
33 unsigned char buf[MAX_LENGTH];
34 long long align_int;
35 #if 0 // TODO: Enable when SDCC suports long double!
36 long double align_fp;
37 #endif
38 } u1, u2;
39 #endif
41 void
42 test (const unsigned char *s1, const unsigned char *s2, int expected)
44 int value = strcmp ((char *) s1, (char *) s2);
46 if (expected < 0 && value >= 0)
47 ASSERT (0);
48 else if (expected == 0 && value != 0)
49 ASSERT (0);
50 else if (expected > 0 && value <= 0)
51 ASSERT (0);
54 void
55 testTortureExecute (void)
57 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
58 size_t off1, off2, len, i;
59 unsigned char *buf1, *buf2;
60 unsigned char *mod1, *mod2;
61 unsigned char *p1, *p2;
63 for (off1 = 0; off1 < MAX_OFFSET; off1++)
64 for (off2 = 0; off2 < MAX_OFFSET; off2++)
65 for (len = 0; len < MAX_TEST; len++)
67 p1 = u1.buf;
68 for (i = 0; i < off1; i++)
69 *p1++ = '\0';
71 buf1 = p1;
72 for (i = 0; i < len; i++)
73 *p1++ = 'a';
75 mod1 = p1;
76 for (i = 0; i < MAX_EXTRA+2; i++)
77 *p1++ = 'x';
79 p2 = u2.buf;
80 for (i = 0; i < off2; i++)
81 *p2++ = '\0';
83 buf2 = p2;
84 for (i = 0; i < len; i++)
85 *p2++ = 'a';
87 mod2 = p2;
88 for (i = 0; i < MAX_EXTRA+2; i++)
89 *p2++ = 'x';
91 mod1[0] = '\0';
92 mod2[0] = '\0';
93 test (buf1, buf2, 0);
95 mod1[0] = 'a';
96 mod1[1] = '\0';
97 mod2[0] = '\0';
98 test (buf1, buf2, +1);
100 mod1[0] = '\0';
101 mod2[0] = 'a';
102 mod2[1] = '\0';
103 test (buf1, buf2, -1);
105 mod1[0] = 'b';
106 mod1[1] = '\0';
107 mod2[0] = 'c';
108 mod2[1] = '\0';
109 test (buf1, buf2, -1);
111 mod1[0] = 'c';
112 mod1[1] = '\0';
113 mod2[0] = 'b';
114 mod2[1] = '\0';
115 test (buf1, buf2, +1);
117 mod1[0] = 'b';
118 mod1[1] = '\0';
119 mod2[0] = (unsigned char)'\251';
120 mod2[1] = '\0';
121 test (buf1, buf2, -1);
123 mod1[0] = (unsigned char)'\251';
124 mod1[1] = '\0';
125 mod2[0] = 'b';
126 mod2[1] = '\0';
127 test (buf1, buf2, +1);
129 mod1[0] = (unsigned char)'\251';
130 mod1[1] = '\0';
131 mod2[0] = (unsigned char)'\252';
132 mod2[1] = '\0';
133 test (buf1, buf2, -1);
135 mod1[0] = (unsigned char)'\252';
136 mod1[1] = '\0';
137 mod2[0] = (unsigned char)'\251';
138 mod2[1] = '\0';
139 test (buf1, buf2, +1);
141 #endif
142 return;