diff options
author | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-08-04 14:38:27 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-08-04 14:38:27 +0000 |
commit | 5e9754afebd0a9433fd5b147fce4d39b687ea88d (patch) | |
tree | 0a6a470d019d3994f8981662fef27725c628f174 | |
parent | 6c167c45b1059150631362a647864ee0ca900a91 (diff) | |
download | gcc-5e9754afebd0a9433fd5b147fce4d39b687ea88d.zip gcc-5e9754afebd0a9433fd5b147fce4d39b687ea88d.tar.gz gcc-5e9754afebd0a9433fd5b147fce4d39b687ea88d.tar.bz2 |
c-lex.c (narrowest_unsigned_type, [...]): Take low/high pair.
* c-lex.c (narrowest_unsigned_type, narrowest_signed_type): Take
low/high pair. Do range checking directly.
(interpret_integer): Adjust.
From-SVN: r85559
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-lex.c | 58 |
2 files changed, 42 insertions, 24 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8cb721f5d..81b4314 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-08-03 Nathan Sidwell <nathan@codesourcery.com> + + * c-lex.c (narrowest_unsigned_type, narrowest_signed_type): Take + low/high pair. Do range checking directly. + (interpret_integer): Adjust. + 2004-08-04 Nick Clifton <nickc@redhat.com> * config/sh/sh.h (TARGET_SWITCHES): Add no-renesas to select the @@ -108,7 +114,7 @@ * config/i386/xmmintrin.h: Include <mm_malloc.h>. 2004-08-03 H.J. Lu <hongjiu.lu@intel.com> - Tanguy Fautrà <tfautre@pandora.be> + Tanguy Fautrà <tfautre@pandora.be> * config/i386/pmm_malloc.h: New file. diff --git a/gcc/c-lex.c b/gcc/c-lex.c index a730652..ee0ae3e 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -62,10 +62,10 @@ int c_lex_string_translate = 1; static tree interpret_integer (const cpp_token *, unsigned int); static tree interpret_float (const cpp_token *, unsigned int); -static enum integer_type_kind - narrowest_unsigned_type (tree, unsigned int); -static enum integer_type_kind - narrowest_signed_type (tree, unsigned int); +static enum integer_type_kind narrowest_unsigned_type + (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); +static enum integer_type_kind narrowest_signed_type + (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); static enum cpp_ttype lex_string (const cpp_token *, tree *, bool); static tree lex_charconst (const cpp_token *); static void update_header_times (const char *); @@ -461,10 +461,13 @@ c_lex (tree *value) } /* Returns the narrowest C-visible unsigned type, starting with the - minimum specified by FLAGS, that can fit VALUE, or itk_none if + minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if there isn't one. */ + static enum integer_type_kind -narrowest_unsigned_type (tree value, unsigned int flags) +narrowest_unsigned_type (unsigned HOST_WIDE_INT low, + unsigned HOST_WIDE_INT high, + unsigned int flags) { enum integer_type_kind itk; @@ -475,20 +478,23 @@ narrowest_unsigned_type (tree value, unsigned int flags) else itk = itk_unsigned_long_long; - /* int_fits_type_p must think the type of its first argument is - wider than its second argument, or it won't do the proper check. */ - TREE_TYPE (value) = widest_unsigned_literal_type_node; - for (; itk < itk_none; itk += 2 /* skip unsigned types */) - if (int_fits_type_p (value, integer_types[itk])) - return itk; + { + tree upper = TYPE_MAX_VALUE (integer_types[itk]); + + if ((unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH (upper) > high + || ((unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH (upper) == high + && TREE_INT_CST_LOW (upper) >= low)) + return itk; + } return itk_none; } /* Ditto, but narrowest signed type. */ static enum integer_type_kind -narrowest_signed_type (tree value, unsigned int flags) +narrowest_signed_type (unsigned HOST_WIDE_INT low, + unsigned HOST_WIDE_INT high, unsigned int flags) { enum integer_type_kind itk; @@ -499,13 +505,16 @@ narrowest_signed_type (tree value, unsigned int flags) else itk = itk_long_long; - /* int_fits_type_p must think the type of its first argument is - wider than its second argument, or it won't do the proper check. */ - TREE_TYPE (value) = widest_unsigned_literal_type_node; for (; itk < itk_none; itk += 2 /* skip signed types */) - if (int_fits_type_p (value, integer_types[itk])) - return itk; + { + tree upper = TYPE_MAX_VALUE (integer_types[itk]); + + if ((unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH (upper) > high + || ((unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH (upper) == high + && TREE_INT_CST_LOW (upper) >= low)) + return itk; + } return itk_none; } @@ -521,18 +530,19 @@ interpret_integer (const cpp_token *token, unsigned int flags) integer = cpp_interpret_integer (parse_in, token, flags); integer = cpp_num_sign_extend (integer, options->precision); - value = build_int_2 (integer.low, integer.high); /* The type of a constant with a U suffix is straightforward. */ if (flags & CPP_N_UNSIGNED) - itk = narrowest_unsigned_type (value, flags); + itk = narrowest_unsigned_type (integer.low, integer.high, flags); else { /* The type of a potentially-signed integer constant varies depending on the base it's in, the standard in use, and the length suffixes. */ - enum integer_type_kind itk_u = narrowest_unsigned_type (value, flags); - enum integer_type_kind itk_s = narrowest_signed_type (value, flags); + enum integer_type_kind itk_u + = narrowest_unsigned_type (integer.low, integer.high, flags); + enum integer_type_kind itk_s + = narrowest_signed_type (integer.low, integer.high, flags); /* In both C89 and C99, octal and hex constants may be signed or unsigned, whichever fits tighter. We do not warn about this @@ -578,11 +588,13 @@ interpret_integer (const cpp_token *token, unsigned int flags) pedwarn ("integer constant is too large for \"%s\" type", (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long"); + value = build_int_2 (integer.low, integer.high); TREE_TYPE (value) = type; /* Convert imaginary to a complex type. */ if (flags & CPP_N_IMAGINARY) - value = build_complex (NULL_TREE, convert (type, integer_zero_node), value); + value = build_complex (NULL_TREE, + convert (type, integer_zero_node), value); return value; } |