* Mainline merge as of 2006-02-16 (@111136).
[official-gcc.git] / gcc / testsuite / g++.dg / opt / range-test-2.C
blob05690bfd07c80b9b098dcb1132fe916a801f71a7
1 // Test fold-const.c (fold_range_test) optimizations.
2 // { dg-do run } */
3 // { dg-options "-O2" } */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <limits.h>
9 #if (INT_MAX == 2147483647) && (INT_MIN == -2147483648) \
10     && (SCHAR_MIN == -128) && (SCHAR_MAX == 127) \
11     && (UCHAR_MIN == 0) && (UCHAR_MAX == 255)
13 #ifndef T
15 enum enum3
17   enum3_zero,
18   enum3_one,
19   enum3_two,
20   enum3_three,
21   enum3_four,
22   enum3_five,
23   enum3_six,
24   enum3_seven
27 int var;
28 void
29 check ()
31   ++var;
34 #define T(IDX, TYPE, TEST, YESARR, NOARR)                               \
35 void __attribute__((noinline))                                          \
36 test##IDX (TYPE x)                                                      \
37 {                                                                       \
38   if (TEST)                                                             \
39     check ();                                                           \
41 #include "range-test-2.C"
42 #undef T
44 int
45 main ()
47   int i, fails = 0;
49 #define C ,
50 #define T(IDX, TYPE, TEST, YESARR, NOARR)                               \
51   {                                                                     \
52     static TYPE yesarr##IDX [] = YESARR;                                \
53     static TYPE noarr##IDX [] = NOARR;                                  \
54     for (i = 0; i < (int) (sizeof (yesarr##IDX) / sizeof (TYPE)); ++i)  \
55       {                                                                 \
56         var = 0;                                                        \
57         test##IDX (yesarr##IDX [i]);                                    \
58         if (var != 1)                                                   \
59           printf ("test" #IDX " failed for yesarr [%u]\n", i), ++fails; \
60       }                                                                 \
61     var = 0;                                                            \
62     for (i = 0; i < (int) (sizeof (noarr##IDX) / sizeof (TYPE)); ++i)   \
63       {                                                                 \
64         test##IDX (noarr##IDX [i]);                                     \
65         if (var != 0)                                                   \
66           printf ("test" #IDX " failed for noarr [%u]\n", i), ++fails;  \
67       }                                                                 \
68   }
69 #include "range-test-2.C"
70 #undef T
72   if (fails)
73     abort ();
75   exit (0);
78 #else
80 /* Use `C' instead of `,' below to separate array entries.  */
82 T(26, enum3, x == enum3_one || x == enum3_two || x == enum3_three,
83   { enum3_one C enum3_two C enum3_three }, { enum3_zero C enum3_four
84     C enum3_five C enum3_six C enum3_seven })
86 #endif
88 #else
90 int
91 main (void)
93   return 0;
96 #endif