struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-20020506-1.c
blob7b418038763a0d87f05071381bf6a1fdd45deb91
1 /*
2 20020506-1.c from the execute part of the gcc torture suite.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #if !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk14)
12 /* Copyright (C) 2002 Free Software Foundation.
14 Test that (A & C1) op C2 optimizations behave correctly where C1 is
15 a constant power of 2, op is == or !=, and C2 is C1 or zero.
17 Written by Roger Sayle, 5th May 2002. */
19 #include <limits.h>
21 void fest1 (signed char c, int set);
22 void fest2 (unsigned char c, int set);
23 void fest3 (short s, int set);
24 void fest4 (unsigned short s, int set);
25 void fest5 (int i, int set);
26 void fest6 (unsigned int i, int set);
27 void fest7 (long long l, int set);
28 void fest8 (unsigned long long l, int set);
30 #ifndef LONG_LONG_MAX
31 #define LONG_LONG_MAX LLONG_MAX
32 #endif
33 #ifndef LONG_LONG_MIN
34 #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
35 #endif
36 #ifndef ULONG_LONG_MAX
37 #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
38 #endif
41 void
42 fest1 (signed char c, int set)
44 if ((c & (SCHAR_MAX+1)) == 0)
46 if (set) ASSERT (0);
48 else
49 if (!set) ASSERT (0);
51 if ((c & (SCHAR_MAX+1)) != 0)
53 if (!set) ASSERT (0);
55 else
56 if (set) ASSERT (0);
58 if ((unsigned char) (c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
60 if (!set) ASSERT (0);
62 else
63 if (set) ASSERT (0);
65 if ((unsigned char) (c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
67 if (set) ASSERT (0);
69 else
70 if (!set) ASSERT (0);
73 void
74 fest2 (unsigned char c, int set)
76 if ((c & (SCHAR_MAX+1)) == 0)
78 if (set) ASSERT (0);
80 else
81 if (!set) ASSERT (0);
83 if ((c & (SCHAR_MAX+1)) != 0)
85 if (!set) ASSERT (0);
87 else
88 if (set) ASSERT (0);
90 if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
92 if (!set) ASSERT (0);
94 else
95 if (set) ASSERT (0);
97 if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
99 if (set) ASSERT (0);
101 else
102 if (!set) ASSERT (0);
105 void
106 fest3 (short s, int set)
108 if ((s & (SHRT_MAX+1)) == 0)
110 if (set) ASSERT (0);
112 else
113 if (!set) ASSERT (0);
115 if ((s & (SHRT_MAX+1)) != 0)
117 if (!set) ASSERT (0);
119 else
120 if (set) ASSERT (0);
122 if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
124 if (!set) ASSERT (0);
126 else
127 if (set) ASSERT (0);
129 if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
131 if (set) ASSERT (0);
133 else
134 if (!set) ASSERT (0);
137 void
138 fest4 (unsigned short s, int set)
140 if ((s & (SHRT_MAX+1)) == 0)
142 if (set) ASSERT (0);
144 else
145 if (!set) ASSERT (0);
147 if ((s & (SHRT_MAX+1)) != 0)
149 if (!set) ASSERT (0);
151 else
152 if (set) ASSERT (0);
154 if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
156 if (!set) ASSERT (0);
158 else
159 if (set) ASSERT (0);
161 if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
163 if (set) ASSERT (0);
165 else
166 if (!set) ASSERT (0);
168 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
169 void
170 fest5 (int i, int set)
172 if ((i & (INT_MAX+1U)) == 0)
174 if (set) ASSERT (0);
176 else
177 if (!set) ASSERT (0);
179 if ((i & (INT_MAX+1U)) != 0)
181 if (!set) ASSERT (0);
183 else
184 if (set) ASSERT (0);
186 if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
188 if (!set) ASSERT (0);
190 else
191 if (set) ASSERT (0);
193 if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
195 if (set) ASSERT (0);
197 else
198 if (!set) ASSERT (0);
201 void
202 fest6 (unsigned int i, int set)
204 if ((i & (INT_MAX+1U)) == 0)
206 if (set) ASSERT (0);
208 else
209 if (!set) ASSERT (0);
211 if ((i & (INT_MAX+1U)) != 0)
213 if (!set) ASSERT (0);
215 else
216 if (set) ASSERT (0);
218 if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
220 if (!set) ASSERT (0);
222 else
223 if (set) ASSERT (0);
225 if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
227 if (set) ASSERT (0);
229 else
230 if (!set) ASSERT (0);
233 void
234 fest7 (long long l, int set)
236 if ((l & (LONG_LONG_MAX+1ULL)) == 0)
238 if (set) ASSERT (0);
240 else
241 if (!set) ASSERT (0);
243 if ((l & (LONG_LONG_MAX+1ULL)) != 0)
245 if (!set) ASSERT (0);
247 else
248 if (set) ASSERT (0);
250 if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
252 ASSERT (set);
254 else
255 if (set) ASSERT (0);
257 if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
259 if (set) ASSERT (0);
261 else
262 ASSERT (set);
265 void
266 fest8 (unsigned long long l, int set)
268 if ((l & (LONG_LONG_MAX+1ULL)) == 0)
270 if (set) ASSERT (0);
272 else
273 if (!set) ASSERT (0);
275 if ((l & (LONG_LONG_MAX+1ULL)) != 0)
277 if (!set) ASSERT (0);
279 else
280 if (set) ASSERT (0);
282 if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
284 if (!set) ASSERT (0);
286 else
287 if (set) ASSERT (0);
289 if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
291 if (set) ASSERT (0);
293 else
294 if (!set) ASSERT (0);
296 #endif
297 #endif
299 void
300 testTortureExecute (void)
302 #if !defined(__SDCC_pic14) && !defined(__SDCC_pic16) && !defined(__SDCC_pdk14)
303 fest1 (0, 0);
304 fest1 (SCHAR_MAX, 0);
305 fest1 (SCHAR_MIN, 1);
306 fest1 (UCHAR_MAX, 1);
308 fest2 (0, 0);
309 fest2 (SCHAR_MAX, 0);
310 fest2 (SCHAR_MIN, 1);
311 fest2 (UCHAR_MAX, 1);
313 fest3 (0, 0);
314 fest3 (SHRT_MAX, 0);
315 fest3 (SHRT_MIN, 1);
316 fest3 (USHRT_MAX, 1);
318 fest4 (0, 0);
319 fest4 (SHRT_MAX, 0);
320 fest4 (SHRT_MIN, 1);
321 fest4 (USHRT_MAX, 1);
322 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
323 fest5 (0, 0);
324 fest5 (INT_MAX, 0);
325 fest5 (INT_MIN, 1);
326 fest5 (UINT_MAX, 1);
328 fest6 (0, 0);
329 fest6 (INT_MAX, 0);
330 fest6 (INT_MIN, 1);
331 fest6 (UINT_MAX, 1);
333 fest7 (0, 0);
334 fest7 (LONG_LONG_MAX, 0);
335 fest7 (LONG_LONG_MIN, 1);
336 fest7 (ULONG_LONG_MAX, 1);
338 fest8 (0, 0);
339 fest8 (LONG_LONG_MAX, 0);
340 fest8 (LONG_LONG_MIN, 1);
341 fest8 (ULONG_LONG_MAX, 1);
343 return;
344 #endif
345 #endif