From 2364e4874303dfbca1a0c827592555757ff821d3 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 4 Aug 2004 14:38:27 +0000 Subject: [PATCH] * c-lex.c (narrowest_unsigned_type, narrowest_signed_type): Take low/high pair. Do range checking directly. (interpret_integer): Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85559 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 +++++++- gcc/c-lex.c | 58 +++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8cb721f..81b4314 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-08-03 Nathan Sidwell + + * 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 * config/sh/sh.h (TARGET_SWITCHES): Add no-renesas to select the @@ -108,7 +114,7 @@ * config/i386/xmmintrin.h: Include . 2004-08-03 H.J. Lu - Tanguy Fautrà + Tanguy Fautrà * 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; } -- 2.7.4