builtins.c (fold_builtin_isdigit): New.
* 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
This commit is contained in:
parent
a69934e07e
commit
61218d193a
@ -1,3 +1,10 @@
|
||||
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
|
||||
|
@ -6767,6 +6767,28 @@ fold_builtin_toascii (tree arglist)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
@ -7257,6 +7279,9 @@ fold_builtin (tree exp)
|
||||
case BUILT_IN_TOASCII:
|
||||
return fold_builtin_toascii (arglist);
|
||||
|
||||
case BUILT_IN_ISDIGIT:
|
||||
return fold_builtin_isdigit (arglist);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -39,12 +39,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
#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
|
||||
|
@ -1787,13 +1787,16 @@ of words in each data entry.
|
||||
@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
|
||||
@ -1802,7 +1805,9 @@ to constants; they are used in @code{case} statements.
|
||||
@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}
|
||||
|
@ -1,3 +1,7 @@
|
||||
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.
|
||||
|
@ -75,6 +75,29 @@ void test(int i)
|
||||
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__ */
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user