PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / 20020506-1.c
blobbcbd45bf6cae3684b5ae97e44793a8e6286a36bf
1 /* Copyright (C) 2002 Free Software Foundation.
3 Test that (A & C1) op C2 optimizations behave correctly where C1 is
4 a constant power of 2, op is == or !=, and C2 is C1 or zero.
6 Written by Roger Sayle, 5th May 2002. */
8 #include <limits.h>
10 extern void abort (void);
12 void test1 (signed char c, int set);
13 void test2 (unsigned char c, int set);
14 void test3 (short s, int set);
15 void test4 (unsigned short s, int set);
16 void test5 (int i, int set);
17 void test6 (unsigned int i, int set);
18 void test7 (long long l, int set);
19 void test8 (unsigned long long l, int set);
21 #ifndef LONG_LONG_MAX
22 #define LONG_LONG_MAX __LONG_LONG_MAX__
23 #endif
24 #ifndef LONG_LONG_MIN
25 #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
26 #endif
27 #ifndef ULONG_LONG_MAX
28 #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
29 #endif
32 void
33 test1 (signed char c, int set)
35 if ((c & (SCHAR_MAX+1)) == 0)
37 if (set) abort ();
39 else
40 if (!set) abort ();
42 if ((c & (SCHAR_MAX+1)) != 0)
44 if (!set) abort ();
46 else
47 if (set) abort ();
49 if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
51 if (!set) abort ();
53 else
54 if (set) abort ();
56 if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
58 if (set) abort ();
60 else
61 if (!set) abort ();
64 void
65 test2 (unsigned char c, int set)
67 if ((c & (SCHAR_MAX+1)) == 0)
69 if (set) abort ();
71 else
72 if (!set) abort ();
74 if ((c & (SCHAR_MAX+1)) != 0)
76 if (!set) abort ();
78 else
79 if (set) abort ();
81 if ((c & (SCHAR_MAX+1)) == (SCHAR_MAX+1))
83 if (!set) abort ();
85 else
86 if (set) abort ();
88 if ((c & (SCHAR_MAX+1)) != (SCHAR_MAX+1))
90 if (set) abort ();
92 else
93 if (!set) abort ();
96 void
97 test3 (short s, int set)
99 if ((s & (SHRT_MAX+1)) == 0)
101 if (set) abort ();
103 else
104 if (!set) abort ();
106 if ((s & (SHRT_MAX+1)) != 0)
108 if (!set) abort ();
110 else
111 if (set) abort ();
113 if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
115 if (!set) abort ();
117 else
118 if (set) abort ();
120 if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
122 if (set) abort ();
124 else
125 if (!set) abort ();
128 void
129 test4 (unsigned short s, int set)
131 if ((s & (SHRT_MAX+1)) == 0)
133 if (set) abort ();
135 else
136 if (!set) abort ();
138 if ((s & (SHRT_MAX+1)) != 0)
140 if (!set) abort ();
142 else
143 if (set) abort ();
145 if ((s & (SHRT_MAX+1)) == (SHRT_MAX+1))
147 if (!set) abort ();
149 else
150 if (set) abort ();
152 if ((s & (SHRT_MAX+1)) != (SHRT_MAX+1))
154 if (set) abort ();
156 else
157 if (!set) abort ();
160 void
161 test5 (int i, int set)
163 if ((i & (INT_MAX+1U)) == 0)
165 if (set) abort ();
167 else
168 if (!set) abort ();
170 if ((i & (INT_MAX+1U)) != 0)
172 if (!set) abort ();
174 else
175 if (set) abort ();
177 if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
179 if (!set) abort ();
181 else
182 if (set) abort ();
184 if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
186 if (set) abort ();
188 else
189 if (!set) abort ();
192 void
193 test6 (unsigned int i, int set)
195 if ((i & (INT_MAX+1U)) == 0)
197 if (set) abort ();
199 else
200 if (!set) abort ();
202 if ((i & (INT_MAX+1U)) != 0)
204 if (!set) abort ();
206 else
207 if (set) abort ();
209 if ((i & (INT_MAX+1U)) == (INT_MAX+1U))
211 if (!set) abort ();
213 else
214 if (set) abort ();
216 if ((i & (INT_MAX+1U)) != (INT_MAX+1U))
218 if (set) abort ();
220 else
221 if (!set) abort ();
224 void
225 test7 (long long l, int set)
227 if ((l & (LONG_LONG_MAX+1ULL)) == 0)
229 if (set) abort ();
231 else
232 if (!set) abort ();
234 if ((l & (LONG_LONG_MAX+1ULL)) != 0)
236 if (!set) abort ();
238 else
239 if (set) abort ();
241 if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
243 if (!set) abort ();
245 else
246 if (set) abort ();
248 if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
250 if (set) abort ();
252 else
253 if (!set) abort ();
256 void
257 test8 (unsigned long long l, int set)
259 if ((l & (LONG_LONG_MAX+1ULL)) == 0)
261 if (set) abort ();
263 else
264 if (!set) abort ();
266 if ((l & (LONG_LONG_MAX+1ULL)) != 0)
268 if (!set) abort ();
270 else
271 if (set) abort ();
273 if ((l & (LONG_LONG_MAX+1ULL)) == (LONG_LONG_MAX+1ULL))
275 if (!set) abort ();
277 else
278 if (set) abort ();
280 if ((l & (LONG_LONG_MAX+1ULL)) != (LONG_LONG_MAX+1ULL))
282 if (set) abort ();
284 else
285 if (!set) abort ();
289 main ()
291 test1 (0, 0);
292 test1 (SCHAR_MAX, 0);
293 test1 (SCHAR_MIN, 1);
294 test1 (UCHAR_MAX, 1);
296 test2 (0, 0);
297 test2 (SCHAR_MAX, 0);
298 test2 (SCHAR_MIN, 1);
299 test2 (UCHAR_MAX, 1);
301 test3 (0, 0);
302 test3 (SHRT_MAX, 0);
303 test3 (SHRT_MIN, 1);
304 test3 (USHRT_MAX, 1);
306 test4 (0, 0);
307 test4 (SHRT_MAX, 0);
308 test4 (SHRT_MIN, 1);
309 test4 (USHRT_MAX, 1);
311 test5 (0, 0);
312 test5 (INT_MAX, 0);
313 test5 (INT_MIN, 1);
314 test5 (UINT_MAX, 1);
316 test6 (0, 0);
317 test6 (INT_MAX, 0);
318 test6 (INT_MIN, 1);
319 test6 (UINT_MAX, 1);
321 test7 (0, 0);
322 test7 (LONG_LONG_MAX, 0);
323 test7 (LONG_LONG_MIN, 1);
324 test7 (ULONG_LONG_MAX, 1);
326 test8 (0, 0);
327 test8 (LONG_LONG_MAX, 0);
328 test8 (LONG_LONG_MIN, 1);
329 test8 (ULONG_LONG_MAX, 1);
331 return 0;