2018-04-09 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / strcmp-1.c
blobc5b4db9fe30c571f4d978f64d38849e87e5ec7b9
1 /* Test strcmp builtin expansion for compilation and proper execution. */
2 /* { dg-do run } */
3 /* { dg-options "-O2" } */
4 /* { dg-require-effective-target ptr32plus } */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #define RUN_TEST(SZ, ALIGN) test_strcmp_ ## SZ ## _ ## ALIGN ()
12 #define DEF_TEST(SZ, ALIGN) \
13 static void test_strcmp_ ## SZ ## _ ## ALIGN (void) { \
14 char one[3 * (SZ > 10 ? SZ : 10)]; \
15 char two[3 * (SZ > 10 ? SZ : 10)]; \
16 char three[8192] __attribute__ ((aligned (4096))); \
17 char four[8192] __attribute__ ((aligned (4096))); \
18 int i,j; \
19 memset(one,0,sizeof(one)); \
20 memset(two,0,sizeof(two)); \
21 memset(three,0,sizeof(three)); \
22 memset(four,0,sizeof(four)); \
23 for (i = 0 ; i < SZ ; i++) \
24 { \
25 int r1; \
26 char *a = one + (i & 1) * ALIGN; \
27 char *b = two + (i & 1) * ALIGN; \
28 memset(a, '-', SZ); \
29 memset(b, '-', SZ); \
30 a[i] = '1'; \
31 b[i] = '2'; \
32 a[SZ] = 0; \
33 b[SZ] = 0; \
34 if (!((r1 = strcmp (b, a)) > 0)) \
35 abort (); \
36 if (!((r1 = strcmp (a, b)) < 0)) \
37 abort (); \
38 b[i] = '1'; \
39 if (!((r1 = strcmp (a, b)) == 0)) \
40 abort (); \
41 for(j = i; j < SZ ; j++) \
42 { \
43 a[j] = '1'; \
44 b[j] = '2'; \
45 } \
46 if (!((r1 = strcmp (b, a)) > 0)) \
47 abort (); \
48 if (!((r1 = strcmp (a, b)) < 0)) \
49 abort (); \
50 for(j = 0; j < i ; j++) \
51 { \
52 memset(a, '-', SZ); \
53 memset(b, '-', SZ); \
54 a[j] = '\0'; \
55 a[j+1] = '1'; \
56 b[j] = '\0'; \
57 b[j+1] = '2'; \
58 if ((r1 = strcmp (b, a)) != 0) \
59 abort (); \
60 } \
61 a = three + 4096 - (SZ / 2 + (i & 1) * ALIGN); \
62 b = four + 4096 - (SZ / 2 + (i & 1) * ALIGN); \
63 memset(a, '-', SZ); \
64 memset(b, '-', SZ); \
65 a[i] = '1'; \
66 b[i] = '2'; \
67 a[SZ] = 0; \
68 b[SZ] = 0; \
69 if (!((r1 = strcmp(b, a)) > 0)) \
70 abort (); \
71 if (!((r1 = strcmp(a, b)) < 0)) \
72 abort (); \
73 b[i] = '1'; \
74 if (!((r1 = strcmp(a, b)) == 0)) \
75 abort (); \
76 } \
79 #ifdef TEST_ALL
80 DEF_TEST(1,1)
81 DEF_TEST(1,2)
82 DEF_TEST(1,4)
83 DEF_TEST(1,8)
84 DEF_TEST(1,16)
85 DEF_TEST(2,1)
86 DEF_TEST(2,2)
87 DEF_TEST(2,4)
88 DEF_TEST(2,8)
89 DEF_TEST(2,16)
90 DEF_TEST(3,1)
91 DEF_TEST(3,2)
92 DEF_TEST(3,4)
93 DEF_TEST(3,8)
94 DEF_TEST(3,16)
95 DEF_TEST(4,1)
96 DEF_TEST(4,2)
97 DEF_TEST(4,4)
98 DEF_TEST(4,8)
99 DEF_TEST(4,16)
100 DEF_TEST(5,1)
101 DEF_TEST(5,2)
102 DEF_TEST(5,4)
103 DEF_TEST(5,8)
104 DEF_TEST(5,16)
105 DEF_TEST(6,1)
106 DEF_TEST(6,2)
107 DEF_TEST(6,4)
108 DEF_TEST(6,8)
109 DEF_TEST(6,16)
110 DEF_TEST(7,1)
111 DEF_TEST(7,2)
112 DEF_TEST(7,4)
113 DEF_TEST(7,8)
114 DEF_TEST(7,16)
115 DEF_TEST(8,1)
116 DEF_TEST(8,2)
117 DEF_TEST(8,4)
118 DEF_TEST(8,8)
119 DEF_TEST(8,16)
120 DEF_TEST(9,1)
121 DEF_TEST(9,2)
122 DEF_TEST(9,4)
123 DEF_TEST(9,8)
124 DEF_TEST(9,16)
125 DEF_TEST(10,1)
126 DEF_TEST(10,2)
127 DEF_TEST(10,4)
128 DEF_TEST(10,8)
129 DEF_TEST(10,16)
130 DEF_TEST(11,1)
131 DEF_TEST(11,2)
132 DEF_TEST(11,4)
133 DEF_TEST(11,8)
134 DEF_TEST(11,16)
135 DEF_TEST(12,1)
136 DEF_TEST(12,2)
137 DEF_TEST(12,4)
138 DEF_TEST(12,8)
139 DEF_TEST(12,16)
140 DEF_TEST(13,1)
141 DEF_TEST(13,2)
142 DEF_TEST(13,4)
143 DEF_TEST(13,8)
144 DEF_TEST(13,16)
145 DEF_TEST(14,1)
146 DEF_TEST(14,2)
147 DEF_TEST(14,4)
148 DEF_TEST(14,8)
149 DEF_TEST(14,16)
150 DEF_TEST(15,1)
151 DEF_TEST(15,2)
152 DEF_TEST(15,4)
153 DEF_TEST(15,8)
154 DEF_TEST(15,16)
155 DEF_TEST(16,1)
156 DEF_TEST(16,2)
157 DEF_TEST(16,4)
158 DEF_TEST(16,8)
159 DEF_TEST(16,16)
160 DEF_TEST(17,1)
161 DEF_TEST(17,2)
162 DEF_TEST(17,4)
163 DEF_TEST(17,8)
164 DEF_TEST(17,16)
165 DEF_TEST(18,1)
166 DEF_TEST(18,2)
167 DEF_TEST(18,4)
168 DEF_TEST(18,8)
169 DEF_TEST(18,16)
170 DEF_TEST(19,1)
171 DEF_TEST(19,2)
172 DEF_TEST(19,4)
173 DEF_TEST(19,8)
174 DEF_TEST(19,16)
175 DEF_TEST(20,1)
176 DEF_TEST(20,2)
177 DEF_TEST(20,4)
178 DEF_TEST(20,8)
179 DEF_TEST(20,16)
180 DEF_TEST(21,1)
181 DEF_TEST(21,2)
182 DEF_TEST(21,4)
183 DEF_TEST(21,8)
184 DEF_TEST(21,16)
185 DEF_TEST(22,1)
186 DEF_TEST(22,2)
187 DEF_TEST(22,4)
188 DEF_TEST(22,8)
189 DEF_TEST(22,16)
190 DEF_TEST(23,1)
191 DEF_TEST(23,2)
192 DEF_TEST(23,4)
193 DEF_TEST(23,8)
194 DEF_TEST(23,16)
195 DEF_TEST(24,1)
196 DEF_TEST(24,2)
197 DEF_TEST(24,4)
198 DEF_TEST(24,8)
199 DEF_TEST(24,16)
200 DEF_TEST(25,1)
201 DEF_TEST(25,2)
202 DEF_TEST(25,4)
203 DEF_TEST(25,8)
204 DEF_TEST(25,16)
205 DEF_TEST(26,1)
206 DEF_TEST(26,2)
207 DEF_TEST(26,4)
208 DEF_TEST(26,8)
209 DEF_TEST(26,16)
210 DEF_TEST(27,1)
211 DEF_TEST(27,2)
212 DEF_TEST(27,4)
213 DEF_TEST(27,8)
214 DEF_TEST(27,16)
215 DEF_TEST(28,1)
216 DEF_TEST(28,2)
217 DEF_TEST(28,4)
218 DEF_TEST(28,8)
219 DEF_TEST(28,16)
220 DEF_TEST(29,1)
221 DEF_TEST(29,2)
222 DEF_TEST(29,4)
223 DEF_TEST(29,8)
224 DEF_TEST(29,16)
225 DEF_TEST(30,1)
226 DEF_TEST(30,2)
227 DEF_TEST(30,4)
228 DEF_TEST(30,8)
229 DEF_TEST(30,16)
230 DEF_TEST(31,1)
231 DEF_TEST(31,2)
232 DEF_TEST(31,4)
233 DEF_TEST(31,8)
234 DEF_TEST(31,16)
235 DEF_TEST(32,1)
236 DEF_TEST(32,2)
237 DEF_TEST(32,4)
238 DEF_TEST(32,8)
239 DEF_TEST(32,16)
240 DEF_TEST(33,1)
241 DEF_TEST(33,2)
242 DEF_TEST(33,4)
243 DEF_TEST(33,8)
244 DEF_TEST(33,16)
245 DEF_TEST(34,1)
246 DEF_TEST(34,2)
247 DEF_TEST(34,4)
248 DEF_TEST(34,8)
249 DEF_TEST(34,16)
250 DEF_TEST(35,1)
251 DEF_TEST(35,2)
252 DEF_TEST(35,4)
253 DEF_TEST(35,8)
254 DEF_TEST(35,16)
255 DEF_TEST(36,1)
256 DEF_TEST(36,2)
257 DEF_TEST(36,4)
258 DEF_TEST(36,8)
259 DEF_TEST(36,16)
260 DEF_TEST(37,1)
261 DEF_TEST(37,2)
262 DEF_TEST(37,4)
263 DEF_TEST(37,8)
264 DEF_TEST(37,16)
265 DEF_TEST(38,1)
266 DEF_TEST(38,2)
267 DEF_TEST(38,4)
268 DEF_TEST(38,8)
269 DEF_TEST(38,16)
270 DEF_TEST(39,1)
271 DEF_TEST(39,2)
272 DEF_TEST(39,4)
273 DEF_TEST(39,8)
274 DEF_TEST(39,16)
275 DEF_TEST(40,1)
276 DEF_TEST(40,2)
277 DEF_TEST(40,4)
278 DEF_TEST(40,8)
279 DEF_TEST(40,16)
280 DEF_TEST(41,1)
281 DEF_TEST(41,2)
282 DEF_TEST(41,4)
283 DEF_TEST(41,8)
284 DEF_TEST(41,16)
285 DEF_TEST(42,1)
286 DEF_TEST(42,2)
287 DEF_TEST(42,4)
288 DEF_TEST(42,8)
289 DEF_TEST(42,16)
290 DEF_TEST(43,1)
291 DEF_TEST(43,2)
292 DEF_TEST(43,4)
293 DEF_TEST(43,8)
294 DEF_TEST(43,16)
295 DEF_TEST(44,1)
296 DEF_TEST(44,2)
297 DEF_TEST(44,4)
298 DEF_TEST(44,8)
299 DEF_TEST(44,16)
300 DEF_TEST(45,1)
301 DEF_TEST(45,2)
302 DEF_TEST(45,4)
303 DEF_TEST(45,8)
304 DEF_TEST(45,16)
305 DEF_TEST(46,1)
306 DEF_TEST(46,2)
307 DEF_TEST(46,4)
308 DEF_TEST(46,8)
309 DEF_TEST(46,16)
310 DEF_TEST(47,1)
311 DEF_TEST(47,2)
312 DEF_TEST(47,4)
313 DEF_TEST(47,8)
314 DEF_TEST(47,16)
315 DEF_TEST(48,1)
316 DEF_TEST(48,2)
317 DEF_TEST(48,4)
318 DEF_TEST(48,8)
319 DEF_TEST(48,16)
320 DEF_TEST(49,1)
321 DEF_TEST(49,2)
322 DEF_TEST(49,4)
323 DEF_TEST(49,8)
324 DEF_TEST(49,16)
325 DEF_TEST(100,1)
326 DEF_TEST(100,2)
327 DEF_TEST(100,4)
328 DEF_TEST(100,8)
329 DEF_TEST(100,16)
330 #else
331 DEF_TEST(3,1)
332 DEF_TEST(4,1)
333 DEF_TEST(4,2)
334 DEF_TEST(4,4)
335 DEF_TEST(5,1)
336 DEF_TEST(6,1)
337 DEF_TEST(7,1)
338 DEF_TEST(8,1)
339 DEF_TEST(8,2)
340 DEF_TEST(8,4)
341 DEF_TEST(8,8)
342 DEF_TEST(9,1)
343 DEF_TEST(16,1)
344 DEF_TEST(16,2)
345 DEF_TEST(16,4)
346 DEF_TEST(16,8)
347 DEF_TEST(16,16)
348 DEF_TEST(32,1)
349 DEF_TEST(32,2)
350 DEF_TEST(32,4)
351 DEF_TEST(32,8)
352 DEF_TEST(32,16)
353 DEF_TEST(100,1)
354 DEF_TEST(100,2)
355 DEF_TEST(100,4)
356 DEF_TEST(100,8)
357 DEF_TEST(100,16)
358 #endif
361 main(int argc, char **argv)
364 #ifdef TEST_ALL
365 RUN_TEST(1,1);
366 RUN_TEST(1,2);
367 RUN_TEST(1,4);
368 RUN_TEST(1,8);
369 RUN_TEST(1,16);
370 RUN_TEST(2,1);
371 RUN_TEST(2,2);
372 RUN_TEST(2,4);
373 RUN_TEST(2,8);
374 RUN_TEST(2,16);
375 RUN_TEST(3,1);
376 RUN_TEST(3,2);
377 RUN_TEST(3,4);
378 RUN_TEST(3,8);
379 RUN_TEST(3,16);
380 RUN_TEST(4,1);
381 RUN_TEST(4,2);
382 RUN_TEST(4,4);
383 RUN_TEST(4,8);
384 RUN_TEST(4,16);
385 RUN_TEST(5,1);
386 RUN_TEST(5,2);
387 RUN_TEST(5,4);
388 RUN_TEST(5,8);
389 RUN_TEST(5,16);
390 RUN_TEST(6,1);
391 RUN_TEST(6,2);
392 RUN_TEST(6,4);
393 RUN_TEST(6,8);
394 RUN_TEST(6,16);
395 RUN_TEST(7,1);
396 RUN_TEST(7,2);
397 RUN_TEST(7,4);
398 RUN_TEST(7,8);
399 RUN_TEST(7,16);
400 RUN_TEST(8,1);
401 RUN_TEST(8,2);
402 RUN_TEST(8,4);
403 RUN_TEST(8,8);
404 RUN_TEST(8,16);
405 RUN_TEST(9,1);
406 RUN_TEST(9,2);
407 RUN_TEST(9,4);
408 RUN_TEST(9,8);
409 RUN_TEST(9,16);
410 RUN_TEST(10,1);
411 RUN_TEST(10,2);
412 RUN_TEST(10,4);
413 RUN_TEST(10,8);
414 RUN_TEST(10,16);
415 RUN_TEST(11,1);
416 RUN_TEST(11,2);
417 RUN_TEST(11,4);
418 RUN_TEST(11,8);
419 RUN_TEST(11,16);
420 RUN_TEST(12,1);
421 RUN_TEST(12,2);
422 RUN_TEST(12,4);
423 RUN_TEST(12,8);
424 RUN_TEST(12,16);
425 RUN_TEST(13,1);
426 RUN_TEST(13,2);
427 RUN_TEST(13,4);
428 RUN_TEST(13,8);
429 RUN_TEST(13,16);
430 RUN_TEST(14,1);
431 RUN_TEST(14,2);
432 RUN_TEST(14,4);
433 RUN_TEST(14,8);
434 RUN_TEST(14,16);
435 RUN_TEST(15,1);
436 RUN_TEST(15,2);
437 RUN_TEST(15,4);
438 RUN_TEST(15,8);
439 RUN_TEST(15,16);
440 RUN_TEST(16,1);
441 RUN_TEST(16,2);
442 RUN_TEST(16,4);
443 RUN_TEST(16,8);
444 RUN_TEST(16,16);
445 RUN_TEST(17,1);
446 RUN_TEST(17,2);
447 RUN_TEST(17,4);
448 RUN_TEST(17,8);
449 RUN_TEST(17,16);
450 RUN_TEST(18,1);
451 RUN_TEST(18,2);
452 RUN_TEST(18,4);
453 RUN_TEST(18,8);
454 RUN_TEST(18,16);
455 RUN_TEST(19,1);
456 RUN_TEST(19,2);
457 RUN_TEST(19,4);
458 RUN_TEST(19,8);
459 RUN_TEST(19,16);
460 RUN_TEST(20,1);
461 RUN_TEST(20,2);
462 RUN_TEST(20,4);
463 RUN_TEST(20,8);
464 RUN_TEST(20,16);
465 RUN_TEST(21,1);
466 RUN_TEST(21,2);
467 RUN_TEST(21,4);
468 RUN_TEST(21,8);
469 RUN_TEST(21,16);
470 RUN_TEST(22,1);
471 RUN_TEST(22,2);
472 RUN_TEST(22,4);
473 RUN_TEST(22,8);
474 RUN_TEST(22,16);
475 RUN_TEST(23,1);
476 RUN_TEST(23,2);
477 RUN_TEST(23,4);
478 RUN_TEST(23,8);
479 RUN_TEST(23,16);
480 RUN_TEST(24,1);
481 RUN_TEST(24,2);
482 RUN_TEST(24,4);
483 RUN_TEST(24,8);
484 RUN_TEST(24,16);
485 RUN_TEST(25,1);
486 RUN_TEST(25,2);
487 RUN_TEST(25,4);
488 RUN_TEST(25,8);
489 RUN_TEST(25,16);
490 RUN_TEST(26,1);
491 RUN_TEST(26,2);
492 RUN_TEST(26,4);
493 RUN_TEST(26,8);
494 RUN_TEST(26,16);
495 RUN_TEST(27,1);
496 RUN_TEST(27,2);
497 RUN_TEST(27,4);
498 RUN_TEST(27,8);
499 RUN_TEST(27,16);
500 RUN_TEST(28,1);
501 RUN_TEST(28,2);
502 RUN_TEST(28,4);
503 RUN_TEST(28,8);
504 RUN_TEST(28,16);
505 RUN_TEST(29,1);
506 RUN_TEST(29,2);
507 RUN_TEST(29,4);
508 RUN_TEST(29,8);
509 RUN_TEST(29,16);
510 RUN_TEST(30,1);
511 RUN_TEST(30,2);
512 RUN_TEST(30,4);
513 RUN_TEST(30,8);
514 RUN_TEST(30,16);
515 RUN_TEST(31,1);
516 RUN_TEST(31,2);
517 RUN_TEST(31,4);
518 RUN_TEST(31,8);
519 RUN_TEST(31,16);
520 RUN_TEST(32,1);
521 RUN_TEST(32,2);
522 RUN_TEST(32,4);
523 RUN_TEST(32,8);
524 RUN_TEST(32,16);
525 RUN_TEST(33,1);
526 RUN_TEST(33,2);
527 RUN_TEST(33,4);
528 RUN_TEST(33,8);
529 RUN_TEST(33,16);
530 RUN_TEST(34,1);
531 RUN_TEST(34,2);
532 RUN_TEST(34,4);
533 RUN_TEST(34,8);
534 RUN_TEST(34,16);
535 RUN_TEST(35,1);
536 RUN_TEST(35,2);
537 RUN_TEST(35,4);
538 RUN_TEST(35,8);
539 RUN_TEST(35,16);
540 RUN_TEST(36,1);
541 RUN_TEST(36,2);
542 RUN_TEST(36,4);
543 RUN_TEST(36,8);
544 RUN_TEST(36,16);
545 RUN_TEST(37,1);
546 RUN_TEST(37,2);
547 RUN_TEST(37,4);
548 RUN_TEST(37,8);
549 RUN_TEST(37,16);
550 RUN_TEST(38,1);
551 RUN_TEST(38,2);
552 RUN_TEST(38,4);
553 RUN_TEST(38,8);
554 RUN_TEST(38,16);
555 RUN_TEST(39,1);
556 RUN_TEST(39,2);
557 RUN_TEST(39,4);
558 RUN_TEST(39,8);
559 RUN_TEST(39,16);
560 RUN_TEST(40,1);
561 RUN_TEST(40,2);
562 RUN_TEST(40,4);
563 RUN_TEST(40,8);
564 RUN_TEST(40,16);
565 RUN_TEST(41,1);
566 RUN_TEST(41,2);
567 RUN_TEST(41,4);
568 RUN_TEST(41,8);
569 RUN_TEST(41,16);
570 RUN_TEST(42,1);
571 RUN_TEST(42,2);
572 RUN_TEST(42,4);
573 RUN_TEST(42,8);
574 RUN_TEST(42,16);
575 RUN_TEST(43,1);
576 RUN_TEST(43,2);
577 RUN_TEST(43,4);
578 RUN_TEST(43,8);
579 RUN_TEST(43,16);
580 RUN_TEST(44,1);
581 RUN_TEST(44,2);
582 RUN_TEST(44,4);
583 RUN_TEST(44,8);
584 RUN_TEST(44,16);
585 RUN_TEST(45,1);
586 RUN_TEST(45,2);
587 RUN_TEST(45,4);
588 RUN_TEST(45,8);
589 RUN_TEST(45,16);
590 RUN_TEST(46,1);
591 RUN_TEST(46,2);
592 RUN_TEST(46,4);
593 RUN_TEST(46,8);
594 RUN_TEST(46,16);
595 RUN_TEST(47,1);
596 RUN_TEST(47,2);
597 RUN_TEST(47,4);
598 RUN_TEST(47,8);
599 RUN_TEST(47,16);
600 RUN_TEST(48,1);
601 RUN_TEST(48,2);
602 RUN_TEST(48,4);
603 RUN_TEST(48,8);
604 RUN_TEST(48,16);
605 RUN_TEST(49,1);
606 RUN_TEST(49,2);
607 RUN_TEST(49,4);
608 RUN_TEST(49,8);
609 RUN_TEST(49,16);
610 #else
611 RUN_TEST(3,1);
612 RUN_TEST(4,1);
613 RUN_TEST(4,2);
614 RUN_TEST(4,4);
615 RUN_TEST(5,1);
616 RUN_TEST(6,1);
617 RUN_TEST(7,1);
618 RUN_TEST(8,1);
619 RUN_TEST(8,2);
620 RUN_TEST(8,4);
621 RUN_TEST(8,8);
622 RUN_TEST(9,1);
623 RUN_TEST(16,1);
624 RUN_TEST(16,2);
625 RUN_TEST(16,4);
626 RUN_TEST(16,8);
627 RUN_TEST(16,16);
628 RUN_TEST(32,1);
629 RUN_TEST(32,2);
630 RUN_TEST(32,4);
631 RUN_TEST(32,8);
632 RUN_TEST(32,16);
633 #endif
634 return 0;