PR ipa/61602
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-ctype-2.c
blob7046aad65625c4ba4b40f87d0d4f5338bc4152e0
1 /* Copyright (C) 2004 Free Software Foundation.
3 Verify that built-in ctype transformations are done correctly by
4 the compiler.
6 Written by Kaveh Ghazi, 2004-04-05. */
8 /* { dg-do link } */
10 extern void link_failure_var(void);
12 void test(int i)
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()
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()
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()
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()
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);
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__);
57 /* This ctype call should transform into another expression. */
58 if (isascii(i) != ((i & ~0x7f) == 0))
59 link_failure_var();
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);
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__);
74 /* This ctype call should transform into another expression. */
75 if (toascii(i) != (i & 0x7f))
76 link_failure_var();
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');
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__);
98 /* This ctype call should transform into another expression. */
99 if (isdigit(i) != ((unsigned)i - '0' <= 9))
100 link_failure_var();
101 #endif /* __OPTIMIZE__ */
104 int main (void)
106 return 0;