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
This commit is contained in:
Nathan Sidwell 2004-08-04 14:38:27 +00:00
parent 6c167c45b1
commit 5e9754afeb
2 changed files with 42 additions and 24 deletions

View file

@ -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> 2004-08-04 Nick Clifton <nickc@redhat.com>
* config/sh/sh.h (TARGET_SWITCHES): Add no-renesas to select the * config/sh/sh.h (TARGET_SWITCHES): Add no-renesas to select the
@ -108,7 +114,7 @@
* config/i386/xmmintrin.h: Include <mm_malloc.h>. * config/i386/xmmintrin.h: Include <mm_malloc.h>.
2004-08-03 H.J. Lu <hongjiu.lu@intel.com> 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. * config/i386/pmm_malloc.h: New file.

View file

@ -62,10 +62,10 @@ int c_lex_string_translate = 1;
static tree interpret_integer (const cpp_token *, unsigned int); static tree interpret_integer (const cpp_token *, unsigned int);
static tree interpret_float (const cpp_token *, unsigned int); static tree interpret_float (const cpp_token *, unsigned int);
static enum integer_type_kind static enum integer_type_kind narrowest_unsigned_type
narrowest_unsigned_type (tree, unsigned int); (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
static enum integer_type_kind static enum integer_type_kind narrowest_signed_type
narrowest_signed_type (tree, unsigned int); (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
static enum cpp_ttype lex_string (const cpp_token *, tree *, bool); static enum cpp_ttype lex_string (const cpp_token *, tree *, bool);
static tree lex_charconst (const cpp_token *); static tree lex_charconst (const cpp_token *);
static void update_header_times (const char *); 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 /* 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. */ there isn't one. */
static enum integer_type_kind 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; enum integer_type_kind itk;
@ -475,20 +478,23 @@ narrowest_unsigned_type (tree value, unsigned int flags)
else else
itk = itk_unsigned_long_long; 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 */) for (; itk < itk_none; itk += 2 /* skip unsigned types */)
if (int_fits_type_p (value, integer_types[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;
}
return itk_none; return itk_none;
} }
/* Ditto, but narrowest signed type. */ /* Ditto, but narrowest signed type. */
static enum integer_type_kind 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; enum integer_type_kind itk;
@ -499,13 +505,16 @@ narrowest_signed_type (tree value, unsigned int flags)
else else
itk = itk_long_long; 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 */) for (; itk < itk_none; itk += 2 /* skip signed types */)
if (int_fits_type_p (value, integer_types[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;
}
return itk_none; 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_interpret_integer (parse_in, token, flags);
integer = cpp_num_sign_extend (integer, options->precision); 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. */ /* The type of a constant with a U suffix is straightforward. */
if (flags & CPP_N_UNSIGNED) if (flags & CPP_N_UNSIGNED)
itk = narrowest_unsigned_type (value, flags); itk = narrowest_unsigned_type (integer.low, integer.high, flags);
else else
{ {
/* The type of a potentially-signed integer constant varies /* The type of a potentially-signed integer constant varies
depending on the base it's in, the standard in use, and the depending on the base it's in, the standard in use, and the
length suffixes. */ length suffixes. */
enum integer_type_kind itk_u = narrowest_unsigned_type (value, flags); enum integer_type_kind itk_u
enum integer_type_kind itk_s = narrowest_signed_type (value, flags); = 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 /* In both C89 and C99, octal and hex constants may be signed or
unsigned, whichever fits tighter. We do not warn about this 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", pedwarn ("integer constant is too large for \"%s\" type",
(flags & CPP_N_UNSIGNED) ? "unsigned long" : "long"); (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
value = build_int_2 (integer.low, integer.high);
TREE_TYPE (value) = type; TREE_TYPE (value) = type;
/* Convert imaginary to a complex type. */ /* Convert imaginary to a complex type. */
if (flags & CPP_N_IMAGINARY) 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; return value;
} }