* builtins.c (fold_builtin_isdigit): New.
(fold_builtin): Handle BUILT_IN_ISDIGIT.
* defaults.h: Add TARGET_DIGIT0 and sort.
* doc/tm.texi: Add TARGET_BS and TARGET_DIGIT0.
testsuite:
* gcc.dg/torture/builtin-ctype-2.c: Test builtin isdigit.
From-SVN: r80681
2004-04-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+ * builtins.c (fold_builtin_isdigit): New.
+ (fold_builtin): Handle BUILT_IN_ISDIGIT.
+ * defaults.h: Add TARGET_DIGIT0 and sort.
+ * doc/tm.texi: Add TARGET_BS and TARGET_DIGIT0.
+
+2004-04-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
* builtins.c (fold_builtin_cabs, fold_builtin): Use
`mathfn_built_in' to determine the new builtin.
* fold-const.c (fold): Likewise.
}
}
+/* Fold a call to builtin isdigit. */
+
+static tree
+fold_builtin_isdigit (tree arglist)
+{
+ if (! validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE))
+ return 0;
+ else
+ {
+ /* Transform isdigit(c) -> (unsigned)(c) - '0' <= 9. */
+ /* According to the C standard, isdigit is unaffected by locale. */
+ tree arg = TREE_VALUE (arglist);
+ arg = build1 (NOP_EXPR, unsigned_type_node, arg);
+ arg = build (MINUS_EXPR, unsigned_type_node, arg,
+ fold (build1 (NOP_EXPR, unsigned_type_node,
+ build_int_2 (TARGET_DIGIT0, 0))));
+ arg = build (LE_EXPR, integer_type_node, arg,
+ fold (build1 (NOP_EXPR, unsigned_type_node,
+ build_int_2 (9, 0))));
+ return fold (arg);
+ }
+}
/* Used by constant folding to eliminate some builtin calls early. EXP is
the CALL_EXPR of a call to a builtin function. */
case BUILT_IN_TOASCII:
return fold_builtin_toascii (arglist);
+ case BUILT_IN_ISDIGIT:
+ return fold_builtin_isdigit (arglist);
+
default:
break;
}
#ifndef TARGET_BELL
# define TARGET_BELL 007
# define TARGET_BS 010
-# define TARGET_TAB 011
-# define TARGET_NEWLINE 012
-# define TARGET_VT 013
-# define TARGET_FF 014
# define TARGET_CR 015
+# define TARGET_DIGIT0 060
# define TARGET_ESC 033
+# define TARGET_FF 014
+# define TARGET_NEWLINE 012
+# define TARGET_TAB 011
+# define TARGET_VT 013
#endif
/* Store in OUTPUT a string (made with alloca) containing an
@section Target Character Escape Sequences
@cindex escape sequences
-By default, GCC assumes that the C character escape sequences take on
-their ASCII values for the target. If this is not correct, you must
-explicitly define all of the macros below. All of them must evaluate
-to constants; they are used in @code{case} statements.
+By default, GCC assumes that the C character escape sequences and other
+characters take on their ASCII values for the target. If this is not
+correct, you must explicitly define all of the macros below. All of
+them must evaluate to constants; they are used in @code{case}
+statements.
@findex TARGET_BELL
+@findex TARGET_BS
@findex TARGET_CR
+@findex TARGET_DIGIT0
@findex TARGET_ESC
@findex TARGET_FF
@findex TARGET_NEWLINE
@multitable {@code{TARGET_NEWLINE}} {Escape} {ASCII character}
@item Macro @tab Escape @tab ASCII character
@item @code{TARGET_BELL} @tab @kbd{\a} @tab @code{07}, @code{BEL}
+@item @code{TARGET_BS} @tab @kbd{\b} @tab @code{08}, @code{BS}
@item @code{TARGET_CR} @tab @kbd{\r} @tab @code{0D}, @code{CR}
+@item @code{TARGET_DIGIT0} @tab @kbd{0} @tab @code{30}, @code{ZERO}
@item @code{TARGET_ESC} @tab @kbd{\e}, @kbd{\E} @tab @code{1B}, @code{ESC}
@item @code{TARGET_FF} @tab @kbd{\f} @tab @code{0C}, @code{FF}
@item @code{TARGET_NEWLINE} @tab @kbd{\n} @tab @code{0A}, @code{LF}
+2004-04-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gcc.dg/torture/builtin-ctype-2.c: Test builtin isdigit.
+
2004-04-13 Uros Bizjak <uros@kss-loka.si>:
* gcc.dg/i386-387-1.c: Add new test for __builtin_tan.
if (toascii(i) != (i & 0x7f))
link_failure_var();
+ TEST_CTYPE_CST_TRUE (isdigit, '0');
+ TEST_CTYPE_CST_TRUE (isdigit, '1');
+ TEST_CTYPE_CST_TRUE (isdigit, '2');
+ TEST_CTYPE_CST_TRUE (isdigit, '3');
+ TEST_CTYPE_CST_TRUE (isdigit, '4');
+ TEST_CTYPE_CST_TRUE (isdigit, '5');
+ TEST_CTYPE_CST_TRUE (isdigit, '6');
+ TEST_CTYPE_CST_TRUE (isdigit, '7');
+ TEST_CTYPE_CST_TRUE (isdigit, '8');
+ TEST_CTYPE_CST_TRUE (isdigit, '9');
+
+ TEST_CTYPE_CST_FALSE (isdigit, '0'-1);
+ TEST_CTYPE_CST_FALSE (isdigit, '9'+1);
+ TEST_CTYPE_CST_FALSE (isdigit, -1);
+ TEST_CTYPE_CST_FALSE (isdigit, 0);
+ TEST_CTYPE_CST_FALSE (isdigit, 255);
+ TEST_CTYPE_CST_FALSE (isdigit, 256);
+ TEST_CTYPE_CST_FALSE (isdigit, 10000);
+ TEST_CTYPE_CST_FALSE (isdigit, __INT_MAX__);
+
+ /* This ctype call should transform into another expression. */
+ if (isdigit(i) != ((unsigned)i - '0' <= 9))
+ link_failure_var();
#endif /* __OPTIMIZE__ */
}