diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-04-08 14:46:05 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-04-08 14:46:05 +0000 |
commit | d49367d4925de0cd346002f7ca00dacd05d5fe3c (patch) | |
tree | 58cb8f84e8640837503a48120b7778dc2f40a944 /gcc/builtins.c | |
parent | 5a9896f41838369ea1ecb4e28ba85c14ecf2e861 (diff) | |
download | gcc-d49367d4925de0cd346002f7ca00dacd05d5fe3c.tar.gz |
* builtins.c (fold_builtin_isascii, fold_builtin_toascii): New.
(fold_builtin): Handle BUILT_IN_ISASCII and BUILT_IN_TOASCII.
testsuite:
* gcc.dg/torture/builtin-ctype-2.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@80508 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index b0d0d48f2fd..655dd250395 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -6742,6 +6742,43 @@ fold_builtin_signbit (tree exp) return NULL_TREE; } +/* Fold a call to builtin isascii. */ + +static tree +fold_builtin_isascii (tree arglist) +{ + if (! validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE)) + return 0; + else + { + /* Transform isascii(c) -> ((c & ~0x7f) == 0). */ + tree arg = TREE_VALUE (arglist); + + return fold (build (EQ_EXPR, integer_type_node, + build (BIT_AND_EXPR, integer_type_node, arg, + build_int_2 (~ (unsigned HOST_WIDE_INT) 0x7f, + ~ (HOST_WIDE_INT) 0)), + integer_zero_node)); + } +} + +/* Fold a call to builtin toascii. */ + +static tree +fold_builtin_toascii (tree arglist) +{ + if (! validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE)) + return 0; + else + { + /* Transform toascii(c) -> (c & 0x7f). */ + tree arg = TREE_VALUE (arglist); + + return fold (build (BIT_AND_EXPR, integer_type_node, arg, + build_int_2 (0x7f, 0))); + } +} + /* Used by constant folding to eliminate some builtin calls early. EXP is the CALL_EXPR of a call to a builtin function. */ @@ -7236,6 +7273,12 @@ fold_builtin (tree exp) case BUILT_IN_SIGNBITL: return fold_builtin_signbit (exp); + case BUILT_IN_ISASCII: + return fold_builtin_isascii (arglist); + + case BUILT_IN_TOASCII: + return fold_builtin_toascii (arglist); + default: break; } |