OSDN Git Service

PR testsuite/21010
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / torture / builtin-ctype-2.c
1 /* Copyright (C) 2004  Free Software Foundation.
2
3    Verify that built-in ctype transformations are done correctly by
4    the compiler.
5
6    Written by Kaveh Ghazi, 2004-04-05.  */
7
8 /* { dg-do link } */
9
10 extern void link_failure_var(void);
11
12 void test(int i)
13 {
14   /* All of these ctype calls should compile-time evaluate to true.  */
15 #define TEST_CTYPE_CST_TRUE(FN, VALUE) \
16   extern void link_failure_##FN##_cst_true(void); \
17   extern int FN(int); \
18   if (! FN(VALUE)) \
19     link_failure_##FN##_cst_true()
20
21   /* All of these ctype calls should compile-time evaluate to false.  */
22 #define TEST_CTYPE_CST_FALSE(FN, VALUE) \
23   extern void link_failure_##FN##_cst_false(void); \
24   extern int FN(int); \
25   if (FN(VALUE)) \
26     link_failure_##FN##_cst_false()
27   
28   /* All of these ctype calls should compile-time evaluate to true.  */
29 #define TEST_TOCTYPE_CST_TRUE(FN, VALUE) \
30   extern void link_failure_##FN##_cst_true(void); \
31   extern int FN(int); \
32   if (FN(VALUE) != (VALUE)) \
33     link_failure_##FN##_cst_true()
34
35   /* All of these ctype calls should compile-time evaluate to false.  */
36 #define TEST_TOCTYPE_CST_FALSE(FN, VALUE) \
37   extern void link_failure_##FN##_cst_false(void); \
38   extern int FN(int); \
39   if (FN(VALUE) == (VALUE)) \
40     link_failure_##FN##_cst_false()
41   
42 #ifdef __OPTIMIZE__
43   TEST_CTYPE_CST_TRUE (isascii, 0);
44   TEST_CTYPE_CST_TRUE (isascii, 1);
45   TEST_CTYPE_CST_TRUE (isascii, 126);
46   TEST_CTYPE_CST_TRUE (isascii, 127);
47
48   TEST_CTYPE_CST_FALSE (isascii, -1);
49   TEST_CTYPE_CST_FALSE (isascii, 128);
50   TEST_CTYPE_CST_FALSE (isascii, 129);
51   TEST_CTYPE_CST_FALSE (isascii, 255);
52   TEST_CTYPE_CST_FALSE (isascii, 256);
53   TEST_CTYPE_CST_FALSE (isascii, 257);
54   TEST_CTYPE_CST_FALSE (isascii, 10000);
55   TEST_CTYPE_CST_FALSE (isascii, __INT_MAX__);
56   
57   /* This ctype call should transform into another expression.  */
58   if (isascii(i) != ((i & ~0x7f) == 0))
59     link_failure_var();
60
61   TEST_TOCTYPE_CST_TRUE (toascii, 0);
62   TEST_TOCTYPE_CST_TRUE (toascii, 1);
63   TEST_TOCTYPE_CST_TRUE (toascii, 126);
64   TEST_TOCTYPE_CST_TRUE (toascii, 127);
65
66   TEST_TOCTYPE_CST_FALSE (toascii, -1);
67   TEST_TOCTYPE_CST_FALSE (toascii, 128);
68   TEST_TOCTYPE_CST_FALSE (toascii, 129);
69   TEST_TOCTYPE_CST_FALSE (toascii, 255);
70   TEST_TOCTYPE_CST_FALSE (toascii, 256);
71   TEST_TOCTYPE_CST_FALSE (toascii, 10000);
72   TEST_TOCTYPE_CST_FALSE (toascii, __INT_MAX__);
73
74   /* This ctype call should transform into another expression.  */
75   if (toascii(i) != (i & 0x7f))
76     link_failure_var();
77
78   TEST_CTYPE_CST_TRUE (isdigit, '0');
79   TEST_CTYPE_CST_TRUE (isdigit, '1');
80   TEST_CTYPE_CST_TRUE (isdigit, '2');
81   TEST_CTYPE_CST_TRUE (isdigit, '3');
82   TEST_CTYPE_CST_TRUE (isdigit, '4');
83   TEST_CTYPE_CST_TRUE (isdigit, '5');
84   TEST_CTYPE_CST_TRUE (isdigit, '6');
85   TEST_CTYPE_CST_TRUE (isdigit, '7');
86   TEST_CTYPE_CST_TRUE (isdigit, '8');
87   TEST_CTYPE_CST_TRUE (isdigit, '9');
88
89   TEST_CTYPE_CST_FALSE (isdigit, '0'-1);
90   TEST_CTYPE_CST_FALSE (isdigit, '9'+1);
91   TEST_CTYPE_CST_FALSE (isdigit, -1);
92   TEST_CTYPE_CST_FALSE (isdigit, 0);
93   TEST_CTYPE_CST_FALSE (isdigit, 255);
94   TEST_CTYPE_CST_FALSE (isdigit, 256);
95   TEST_CTYPE_CST_FALSE (isdigit, 10000);
96   TEST_CTYPE_CST_FALSE (isdigit, __INT_MAX__);
97   
98   /* This ctype call should transform into another expression.  */
99   if (isdigit(i) != ((unsigned)i - '0' <= 9))
100     link_failure_var();
101 #endif /* __OPTIMIZE__ */
102 }
103
104 int main (void)
105 {
106   return 0;
107 }