Commit ceeedfc1 by Neil Booth Committed by Neil Booth

c-common.c (c_common_init): Override cpplib's default warn_long_long setting.

	* c-common.c (c_common_init): Override cpplib's default
	warn_long_long setting.
	* c-lex.c (lex_number): Replace with interpret_integer,
	interpret_float, narrowest_unsigned_type and
	narrowest_signed_type, taking advantage of the new
	cpplib functionality.
	* cpperror.c (_cpp_begin_message): If a warning is turned
	into an error, avoid printing "warning:".
	* cppexp.c (cpp_num_sign_extend): New.
	* cppinit.c: Update comment.
	* cpplib.h (cpp_num_sign_extend): New.
	* tree.h: Update comment.
testsuite:
	* gcc.dg/wtr-int-type-1.c, gcc.dg/wtr-suffix-1.c,
	gcc.dg/cpp/paste4.c, gcc.dg/cpp/sysmac2.c:
	Update for mofified diagnostics.
	* gcc.dg/c99-intconst-1.c: No longer fail.

From-SVN: r54180
parent 27e511e0
2002-06-02 Neil Booth <neil@daikokuya.demon.co.uk>
* c-common.c (c_common_init): Override cpplib's default
warn_long_long setting.
* c-lex.c (lex_number): Replace with interpret_integer,
interpret_float, narrowest_unsigned_type and
narrowest_signed_type, taking advantage of the new
cpplib functionality.
* cpperror.c (_cpp_begin_message): If a warning is turned
into an error, avoid printing "warning:".
* cppexp.c (cpp_num_sign_extend): New.
* cppinit.c: Update comment.
* cpplib.h (cpp_num_sign_extend): New.
* tree.h: Update comment.
2002-06-02 Gabriel Dos Reis <gdr@codesourcery.com> 2002-06-02 Gabriel Dos Reis <gdr@codesourcery.com>
* diagnostic.h (struct diagnostic_context): Add new member * diagnostic.h (struct diagnostic_context): Add new member
......
...@@ -4510,6 +4510,10 @@ c_common_init (filename) ...@@ -4510,6 +4510,10 @@ c_common_init (filename)
options->warn_multichar = warn_multichar; options->warn_multichar = warn_multichar;
options->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS; options->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
/* We want -Wno-long-long to override -pedantic -std=non-c99
whatever the ordering. */
options->warn_long_long = warn_long_long && !flag_isoc99 && pedantic;
/* Register preprocessor built-ins before calls to /* Register preprocessor built-ins before calls to
cpp_main_file. */ cpp_main_file. */
cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins; cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins;
......
...@@ -73,7 +73,12 @@ int c_header_level; /* depth in C headers - C++ only */ ...@@ -73,7 +73,12 @@ int c_header_level; /* depth in C headers - C++ only */
/* Nonzero tells yylex to ignore \ in string constants. */ /* Nonzero tells yylex to ignore \ in string constants. */
static int ignore_escape_flag; static int ignore_escape_flag;
static tree lex_number PARAMS ((const char *, unsigned int)); static tree interpret_integer PARAMS ((const cpp_token *, unsigned int));
static tree interpret_float PARAMS ((const cpp_token *, unsigned int));
static enum integer_type_kind
narrowest_unsigned_type PARAMS ((tree, unsigned int));
static enum integer_type_kind
narrowest_signed_type PARAMS ((tree, unsigned int));
static tree lex_string PARAMS ((const unsigned char *, unsigned int, static tree lex_string PARAMS ((const unsigned char *, unsigned int,
int)); int));
static tree lex_charconst PARAMS ((const cpp_token *)); static tree lex_charconst PARAMS ((const cpp_token *));
...@@ -664,26 +669,6 @@ utf8_extend_token (c) ...@@ -664,26 +669,6 @@ utf8_extend_token (c)
while (shift); while (shift);
} }
#endif #endif
#if 0
struct try_type
{
tree *const node_var;
const char unsigned_flag;
const char long_flag;
const char long_long_flag;
};
struct try_type type_sequence[] =
{
{ &integer_type_node, 0, 0, 0},
{ &unsigned_type_node, 1, 0, 0},
{ &long_integer_type_node, 0, 1, 0},
{ &long_unsigned_type_node, 1, 1, 0},
{ &long_long_integer_type_node, 0, 1, 1},
{ &long_long_unsigned_type_node, 1, 1, 1}
};
#endif /* 0 */
int int
c_lex (value) c_lex (value)
...@@ -719,7 +704,27 @@ c_lex (value) ...@@ -719,7 +704,27 @@ c_lex (value)
break; break;
case CPP_NUMBER: case CPP_NUMBER:
*value = lex_number ((const char *)tok->val.str.text, tok->val.str.len); {
unsigned int flags = cpp_classify_number (parse_in, tok);
switch (flags & CPP_N_CATEGORY)
{
case CPP_N_INVALID:
/* cpplib has issued an error. */
break;
case CPP_N_INTEGER:
*value = interpret_integer (tok, flags);
break;
case CPP_N_FLOATING:
*value = interpret_float (tok, flags);
break;
default:
abort ();
}
}
break; break;
case CPP_CHAR: case CPP_CHAR:
...@@ -745,469 +750,208 @@ c_lex (value) ...@@ -745,469 +750,208 @@ c_lex (value)
return tok->type; return tok->type;
} }
#define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0) /* Returns the narrowest C-visible unsigned type, starting with the
minimum specified by FLAGS, that can fit VALUE, or itk_none if
static tree there isn't one. */
lex_number (str, len) static enum integer_type_kind
const char *str; narrowest_unsigned_type (value, flags)
unsigned int len; tree value;
unsigned int flags;
{ {
int base = 10; enum integer_type_kind itk;
int count = 0;
int largest_digit = 0;
int numdigits = 0;
int overflow = 0;
int c;
tree value;
const char *p;
enum anon1 { NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON } floatflag = NOT_FLOAT;
/* We actually store only HOST_BITS_PER_CHAR bits in each part.
The code below which fills the parts array assumes that a host
int is at least twice as wide as a host char, and that
HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
Two HOST_WIDE_INTs is the largest int literal we can store.
In order to detect overflow below, the number of parts (TOTAL_PARTS)
must be exactly the number of parts needed to hold the bits
of two HOST_WIDE_INTs. */
#define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
unsigned int parts[TOTAL_PARTS];
/* Optimize for most frequent case. */
if (len == 1)
{
if (*str == '0')
return integer_zero_node;
else if (*str == '1')
return integer_one_node;
else
return build_int_2 (*str - '0', 0);
}
for (count = 0; count < TOTAL_PARTS; count++)
parts[count] = 0;
/* len is known to be >1 at this point. */
p = str;
if (len > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
{
base = 16;
p = str + 2;
}
/* The ISDIGIT check is so we are not confused by a suffix on 0. */
else if (str[0] == '0' && ISDIGIT (str[1]))
{
base = 8;
p = str + 1;
}
do
{
c = *p++;
if (c == '.')
{
if (floatflag == AFTER_POINT)
ERROR ("too many decimal points in floating constant");
else if (floatflag == AFTER_EXPON)
ERROR ("decimal point in exponent - impossible!");
else
floatflag = AFTER_POINT;
if (base == 8)
base = 10;
}
else if (c == '_')
/* Possible future extension: silently ignore _ in numbers,
permitting cosmetic grouping - e.g. 0x8000_0000 == 0x80000000
but somewhat easier to read. Ada has this? */
ERROR ("underscore in number");
else
{
int n;
/* It is not a decimal point.
It should be a digit (perhaps a hex digit). */
if (ISDIGIT (c)
|| (base == 16 && ISXDIGIT (c)))
{
n = hex_value (c);
}
else if (base <= 10 && (c == 'e' || c == 'E'))
{
base = 10;
floatflag = AFTER_EXPON;
break;
}
else if (base == 16 && (c == 'p' || c == 'P'))
{
floatflag = AFTER_EXPON;
break; /* start of exponent */
}
else
{
p--;
break; /* start of suffix */
}
if (n >= largest_digit)
largest_digit = n;
numdigits++;
for (count = 0; count < TOTAL_PARTS; count++)
{
parts[count] *= base;
if (count)
{
parts[count]
+= (parts[count-1] >> HOST_BITS_PER_CHAR);
parts[count-1]
&= (1 << HOST_BITS_PER_CHAR) - 1;
}
else
parts[0] += n;
}
/* If the highest-order part overflows (gets larger than
a host char will hold) then the whole number has
overflowed. Record this and truncate the highest-order
part. */
if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
{
overflow = 1;
parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
}
}
}
while (p < str + len);
/* This can happen on input like `int i = 0x;' */
if (numdigits == 0)
ERROR ("numeric constant with no digits");
if (largest_digit >= base)
ERROR ("numeric constant contains digits beyond the radix");
if (floatflag != NOT_FLOAT)
{
tree type;
const char *typename;
int imag, fflag, lflag;
REAL_VALUE_TYPE real;
char *copy;
if (base == 16 && floatflag != AFTER_EXPON)
ERROR ("hexadecimal floating constant has no exponent");
/* Read explicit exponent if any, and put it in tokenbuf. */
if ((base == 10 && ((c == 'e') || (c == 'E')))
|| (base == 16 && (c == 'p' || c == 'P')))
{
if (p < str + len)
c = *p++;
if (p < str + len && (c == '+' || c == '-'))
c = *p++;
/* Exponent is decimal, even if string is a hex float. */
if (! ISDIGIT (c))
ERROR ("floating constant exponent has no digits");
while (p < str + len && ISDIGIT (c))
c = *p++;
if (! ISDIGIT (c))
p--;
}
/* Copy the float constant now; we don't want any suffixes in the if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
string passed to parse_float. */ itk = itk_unsigned_int;
copy = alloca (p - str + 1); else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
memcpy (copy, str, p - str); itk = itk_unsigned_long;
copy[p - str] = '\0'; else
itk = itk_unsigned_long_long;
/* Now parse suffixes. */ /* int_fits_type_p must think the type of its first argument is
fflag = lflag = imag = 0; wider than its second argument, or it won't do the proper check. */
while (p < str + len) TREE_TYPE (value) = widest_unsigned_literal_type_node;
switch (*p++)
{
case 'f': case 'F':
if (fflag)
ERROR ("more than one 'f' suffix on floating constant");
else if (warn_traditional && !in_system_header
&& ! cpp_sys_macro_p (parse_in))
warning ("traditional C rejects the 'f' suffix");
fflag = 1;
break;
case 'l': case 'L': for (; itk < itk_none; itk += 2 /* skip unsigned types */)
if (lflag) if (int_fits_type_p (value, integer_types[itk]))
ERROR ("more than one 'l' suffix on floating constant"); return itk;
else if (warn_traditional && !in_system_header
&& ! cpp_sys_macro_p (parse_in))
warning ("traditional C rejects the 'l' suffix");
lflag = 1; return itk_none;
break; }
case 'i': case 'I': /* Ditto, but narrowest signed type. */
case 'j': case 'J': static enum integer_type_kind
if (imag) narrowest_signed_type (value, flags)
ERROR ("more than one 'i' or 'j' suffix on floating constant"); tree value;
else if (pedantic) unsigned int flags;
pedwarn ("ISO C forbids imaginary numeric constants"); {
imag = 1; enum integer_type_kind itk;
break;
default: if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
ERROR ("invalid suffix on floating constant"); itk = itk_int;
} else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
itk = itk_long;
else
itk = itk_long_long;
type = double_type_node; /* int_fits_type_p must think the type of its first argument is
typename = "double"; wider than its second argument, or it won't do the proper check. */
TREE_TYPE (value) = widest_unsigned_literal_type_node;
if (fflag)
{
if (lflag)
ERROR ("both 'f' and 'l' suffixes on floating constant");
type = float_type_node; for (; itk < itk_none; itk += 2 /* skip signed types */)
typename = "float"; if (int_fits_type_p (value, integer_types[itk]))
} return itk;
else if (lflag)
{
type = long_double_type_node;
typename = "long double";
}
else if (flag_single_precision_constant)
{
type = float_type_node;
typename = "float";
}
/* Warn about this only after we know we're not issuing an error. */ return itk_none;
if (base == 16 && pedantic && !flag_isoc99) }
pedwarn ("hexadecimal floating constants are only valid in C99");
/* The second argument, machine_mode, of REAL_VALUE_ATOF /* Interpret TOKEN, an integer with FLAGS as classified by cpplib. */
tells the desired precision of the binary result static tree
of decimal-to-binary conversion. */ interpret_integer (token, flags)
if (base == 16) const cpp_token *token;
real = REAL_VALUE_HTOF (copy, TYPE_MODE (type)); unsigned int flags;
else {
real = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); tree value, type;
enum integer_type_kind itk;
/* A diagnostic is required here by some ISO C testsuites. cpp_num integer;
This is not pedwarn, because some people don't want cpp_options *options = cpp_get_options (parse_in);
an error for this. */
if (REAL_VALUE_ISINF (real) && pedantic) integer = cpp_interpret_integer (parse_in, token, flags);
warning ("floating point number exceeds range of 'double'"); integer = cpp_num_sign_extend (integer, options->precision);
value = build_int_2_wide (integer.low, integer.high);
/* Create a node with determined type and value. */
if (imag) /* The type of a constant with a U suffix is straightforward. */
value = build_complex (NULL_TREE, convert (type, integer_zero_node), if (flags & CPP_N_UNSIGNED)
build_real (type, real)); itk = narrowest_unsigned_type (value, flags);
else
value = build_real (type, real);
}
else else
{ {
tree trad_type, type; /* The type of a potentially-signed integer constant varies
HOST_WIDE_INT high, low; depending on the base it's in, the standard in use, and the
int spec_unsigned = 0; length suffixes. */
int spec_long = 0; enum integer_type_kind itk_u = narrowest_unsigned_type (value, flags);
int spec_long_long = 0; enum integer_type_kind itk_s = narrowest_signed_type (value, flags);
int spec_imag = 0;
int suffix_lu = 0; /* In both C89 and C99, octal and hex constants may be signed or
int warn = 0, i; unsigned, whichever fits tighter. We do not warn about this
choice differing from the traditional choice, as the constant
trad_type = type = NULL_TREE; is probably a bit pattern and either way will work. */
while (p < str + len) if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
itk = MIN (itk_u, itk_s);
else
{ {
c = *p++; /* In C99, decimal constants are always signed.
switch (c) In C89, decimal constants that don't fit in long have
undefined behaviour; we try to make them unsigned long.
In GCC's extended C89, that last is true of decimal
constants that don't fit in long long, too. */
itk = itk_s;
if (itk_s > itk_u && itk_s > itk_long)
{ {
case 'u': case 'U': if (!flag_isoc99)
if (spec_unsigned)
error ("two 'u' suffixes on integer constant");
else if (warn_traditional && !in_system_header
&& ! cpp_sys_macro_p (parse_in))
warning ("traditional C rejects the 'u' suffix");
spec_unsigned = 1;
if (spec_long)
suffix_lu = 1;
break;
case 'l': case 'L':
if (spec_long)
{ {
if (spec_long_long) if (itk_u < itk_unsigned_long)
error ("three 'l' suffixes on integer constant"); itk_u = itk_unsigned_long;
else if (suffix_lu) itk = itk_u;
error ("'lul' is not a valid integer suffix"); warning ("this decimal constant is unsigned only in ISO C89");
else if (c != spec_long)
error ("'Ll' and 'lL' are not valid integer suffixes");
else if (pedantic && ! flag_isoc99
&& ! in_system_header && warn_long_long)
pedwarn ("ISO C89 forbids long long integer constants");
spec_long_long = 1;
} }
spec_long = c; else if (warn_traditional)
break; warning ("this decimal constant would be unsigned in ISO C89");
case 'i': case 'I': case 'j': case 'J':
if (spec_imag)
error ("more than one 'i' or 'j' suffix on integer constant");
else if (pedantic)
pedwarn ("ISO C forbids imaginary numeric constants");
spec_imag = 1;
break;
default:
ERROR ("invalid suffix on integer constant");
} }
} }
}
/* If the literal overflowed, pedwarn about it now. */ if (itk == itk_none)
if (overflow) /* cpplib has already issued a warning for overflow. */
{ type = ((flags & CPP_N_UNSIGNED)
warn = 1; ? widest_unsigned_literal_type_node
pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2); : widest_integer_literal_type_node);
} else
type = integer_types[itk];
/* This is simplified by the fact that our constant
is always positive. */
high = low = 0;
for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) if (itk > itk_unsigned_long
{ && (flags & CPP_N_WIDTH) != CPP_N_LARGE
high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT && ! in_system_header && ! flag_isoc99)
/ HOST_BITS_PER_CHAR)] pedwarn ("integer constant is too large for \"%s\" type",
<< (i * HOST_BITS_PER_CHAR)); (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
}
value = build_int_2 (low, high); TREE_TYPE (value) = type;
TREE_TYPE (value) = long_long_unsigned_type_node;
/* If warn_traditional, calculate both the ISO type and the /* Convert imaginary to a complex type. */
traditional type, then see if they disagree. */ if (flags & CPP_N_IMAGINARY)
if (warn_traditional) value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
{
/* Traditionally, any constant is signed; but if unsigned is
specified explicitly, obey that. Use the smallest size
with the right number of bits, except for one special
case with decimal constants. */
if (! spec_long && base != 10
&& int_fits_type_p (value, unsigned_type_node))
trad_type = spec_unsigned ? unsigned_type_node : integer_type_node;
/* A decimal constant must be long if it does not fit in
type int. I think this is independent of whether the
constant is signed. */
else if (! spec_long && base == 10
&& int_fits_type_p (value, integer_type_node))
trad_type = spec_unsigned ? unsigned_type_node : integer_type_node;
else if (! spec_long_long)
trad_type = (spec_unsigned
? long_unsigned_type_node
: long_integer_type_node);
else if (int_fits_type_p (value,
spec_unsigned
? long_long_unsigned_type_node
: long_long_integer_type_node))
trad_type = (spec_unsigned
? long_long_unsigned_type_node
: long_long_integer_type_node);
else
trad_type = (spec_unsigned
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
}
/* Calculate the ISO type. */
if (! spec_long && ! spec_unsigned
&& int_fits_type_p (value, integer_type_node))
type = integer_type_node;
else if (! spec_long && (base != 10 || spec_unsigned)
&& int_fits_type_p (value, unsigned_type_node))
type = unsigned_type_node;
else if (! spec_unsigned && !spec_long_long
&& int_fits_type_p (value, long_integer_type_node))
type = long_integer_type_node;
else if (! spec_long_long
&& int_fits_type_p (value, long_unsigned_type_node))
type = long_unsigned_type_node;
else if (! spec_unsigned
&& int_fits_type_p (value, long_long_integer_type_node))
type = long_long_integer_type_node;
else if (int_fits_type_p (value, long_long_unsigned_type_node))
type = long_long_unsigned_type_node;
else if (! spec_unsigned
&& int_fits_type_p (value, widest_integer_literal_type_node))
type = widest_integer_literal_type_node;
else
type = widest_unsigned_literal_type_node;
/* We assume that constants specified in a non-decimal
base are bit patterns, and that the programmer really
meant what they wrote. */
if (warn_traditional && !in_system_header
&& base == 10 && trad_type != type)
{
if (TYPE_PRECISION (trad_type) != TYPE_PRECISION (type))
warning ("width of integer constant is different in traditional C");
else if (TREE_UNSIGNED (trad_type) != TREE_UNSIGNED (type))
warning ("integer constant is unsigned in ISO C, signed in traditional C");
else
warning ("width of integer constant may change on other systems in traditional C");
}
if (pedantic && (flag_isoc99 || !spec_long_long) return value;
&& !warn }
&& ((flag_isoc99
? TYPE_PRECISION (long_long_integer_type_node)
: TYPE_PRECISION (long_integer_type_node)) < TYPE_PRECISION (type)))
{
warn = 1;
pedwarn ("integer constant larger than the maximum value of %s",
(flag_isoc99
? (TREE_UNSIGNED (type)
? _("an unsigned long long int")
: _("a long long int"))
: _("an unsigned long int")));
}
if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) /* Interpret TOKEN, a floating point number with FLAGS as classified
warning ("decimal constant is so large that it is unsigned"); by cpplib. */
static tree
interpret_float (token, flags)
const cpp_token *token;
unsigned int flags;
{
tree type;
tree value;
REAL_VALUE_TYPE real;
char *copy;
size_t copylen;
const char *typename;
if (spec_imag) /* FIXME: make %T work in error/warning, then we don't need typename. */
{ if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
if (TYPE_PRECISION (type) {
<= TYPE_PRECISION (integer_type_node)) type = long_double_type_node;
value = build_complex (NULL_TREE, integer_zero_node, typename = "long double";
convert (integer_type_node, value)); }
else else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
ERROR ("complex integer constant is too wide for 'complex int'"); || flag_single_precision_constant)
} {
else type = float_type_node;
TREE_TYPE (value) = type; typename = "float";
}
else
{
type = double_type_node;
typename = "double";
}
/* If it's still an integer (not a complex), and it doesn't /* Copy the constant to a nul-terminated buffer. If the constant
fit in the type we choose for it, then pedwarn. */ has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
can't handle them. */
copylen = token->val.str.len;
if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
/* Must be an F or L suffix. */
copylen--;
if (flags & CPP_N_IMAGINARY)
/* I or J suffix. */
copylen--;
copy = alloca (copylen + 1);
memcpy (copy, token->val.str.text, copylen);
copy[copylen] = '\0';
/* The second argument, machine_mode, of REAL_VALUE_ATOF tells the
desired precision of the binary result of decimal-to-binary
conversion. */
if (flags & CPP_N_HEX)
real = REAL_VALUE_HTOF (copy, TYPE_MODE (type));
else
real = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
if (! warn /* A diagnostic is required for "soft" overflow by some ISO C
&& TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE testsuites. This is not pedwarn, because some people don't want
&& ! int_fits_type_p (value, TREE_TYPE (value))) an error for this.
pedwarn ("integer constant is larger than the maximum value for its type"); ??? That's a dubious reason... is this a mandatory diagnostic or
} isn't it? -- zw, 2001-08-21. */
if (REAL_VALUE_ISINF (real) && pedantic)
warning ("floating constant exceeds range of \"%s\"", typename);
if (p < str + len) /* Create a node with determined type and value. */
error ("missing white space after number '%.*s'", (int) (p - str), str); value = build_real (type, real);
if (flags & CPP_N_IMAGINARY)
value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
return value; return value;
syntax_error:
return integer_zero_node;
} }
static tree static tree
...@@ -1321,7 +1065,7 @@ lex_charconst (token) ...@@ -1321,7 +1065,7 @@ lex_charconst (token)
tree type, value; tree type, value;
unsigned int chars_seen; unsigned int chars_seen;
int unsignedp; int unsignedp;
result = cpp_interpret_charconst (parse_in, token, result = cpp_interpret_charconst (parse_in, token,
&chars_seen, &unsignedp); &chars_seen, &unsignedp);
......
...@@ -92,6 +92,7 @@ _cpp_begin_message (pfile, code, line, column) ...@@ -92,6 +92,7 @@ _cpp_begin_message (pfile, code, line, column)
{ {
if (CPP_OPTION (pfile, inhibit_errors)) if (CPP_OPTION (pfile, inhibit_errors))
return 0; return 0;
level = DL_ERROR;
pfile->errors++; pfile->errors++;
} }
else if (CPP_OPTION (pfile, inhibit_warnings)) else if (CPP_OPTION (pfile, inhibit_warnings))
......
...@@ -995,6 +995,33 @@ num_positive (num, precision) ...@@ -995,6 +995,33 @@ num_positive (num, precision)
return (num.low & (cpp_num_part) 1 << (precision - 1)) == 0; return (num.low & (cpp_num_part) 1 << (precision - 1)) == 0;
} }
/* Sign extend a number, with PRECISION significant bits and all
others assumed clear, to fill out a cpp_num structure. */
cpp_num
cpp_num_sign_extend (num, precision)
cpp_num num;
size_t precision;
{
if (!num.unsignedp)
{
if (precision > PART_PRECISION)
{
precision -= PART_PRECISION;
if (precision < PART_PRECISION
&& (num.high & (cpp_num_part) 1 << (precision - 1)))
num.high |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
}
else if (num.low & (cpp_num_part) 1 << (precision - 1))
{
if (precision < PART_PRECISION)
num.low |= ~(~(cpp_num_part) 0 >> (PART_PRECISION - precision));
num.high = ~(cpp_num_part) 0;
}
}
return num;
}
/* Returns the negative of NUM. */ /* Returns the negative of NUM. */
static cpp_num static cpp_num
num_negate (num, precision) num_negate (num, precision)
......
...@@ -1770,6 +1770,8 @@ cpp_post_options (pfile) ...@@ -1770,6 +1770,8 @@ cpp_post_options (pfile)
if (CPP_OPTION (pfile, cplusplus)) if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0; CPP_OPTION (pfile, warn_traditional) = 0;
/* The compiler front ends override this, but I think this is the
appropriate setting for the library. */
CPP_OPTION (pfile, warn_long_long) = (CPP_OPTION (pfile, pedantic) CPP_OPTION (pfile, warn_long_long) = (CPP_OPTION (pfile, pedantic)
&& !CPP_OPTION (pfile, c99)); && !CPP_OPTION (pfile, c99));
......
...@@ -625,6 +625,10 @@ extern unsigned cpp_classify_number PARAMS ((cpp_reader *, const cpp_token *)); ...@@ -625,6 +625,10 @@ extern unsigned cpp_classify_number PARAMS ((cpp_reader *, const cpp_token *));
extern cpp_num cpp_interpret_integer PARAMS ((cpp_reader *, const cpp_token *, extern cpp_num cpp_interpret_integer PARAMS ((cpp_reader *, const cpp_token *,
unsigned int type)); unsigned int type));
/* Sign extend a number, with PRECISION significant bits and all
others assumed clear, to fill out a cpp_num structure. */
cpp_num cpp_num_sign_extend PARAMS ((cpp_num, size_t));
/* Diagnostic levels. To get a dianostic without associating a /* Diagnostic levels. To get a dianostic without associating a
position in the translation unit with it, use cpp_error_with_line position in the translation unit with it, use cpp_error_with_line
with a line number of zero. */ with a line number of zero. */
......
2002-06-02 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.dg/wtr-int-type-1.c, gcc.dg/wtr-suffix-1.c,
gcc.dg/cpp/paste4.c, gcc.dg/cpp/sysmac2.c:
Update for mofified diagnostics.
* gcc.dg/c99-intconst-1.c: No longer fail.
2002-06-02 Richard Henderson <rth@redhat.com> 2002-06-02 Richard Henderson <rth@redhat.com>
* gcc.dg/uninit-A.c: Remove xfail markers. * gcc.dg/uninit-A.c: Remove xfail markers.
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
/* C99 type selection didn't make it into 3.1, so this test
will fail on one or two entries; which ones depends on the
platform.
{ dg-excess-errors "c99 not yet" } */
#include <limits.h> #include <limits.h>
/* Assertion that constant C is of type T. */ /* Assertion that constant C is of type T. */
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
int main () int main ()
{ {
double d = glue (1.0e, +1); /* { dg-error "floating const|parse error" } */ double d = glue (1.0e, +1); /* { dg-error "exponent|parse error" } */
return 0; return 0;
} }
/* Copyright (C) 2001 Free Software Foundation, Inc. */ /* Copyright (C) 2001 Free Software Foundation, Inc. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-std=gnu99 -pedantic -Wtraditional" } */ /* { dg-options "-std=gnu99 -pedantic -Wtraditional -fno-show-column" } */
/* Tests diagnostics are suppressed for some macros defined in system /* Tests diagnostics are suppressed for some macros defined in system
headers. */ headers. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Note, gcc should omit these warnings in system header files. Note, gcc should omit these warnings in system header files.
By Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 8/22/2000. */ By Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 8/22/2000. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-Wtraditional" } */ /* { dg-options "-std=c99 -Wtraditional" } */
void void
testfunc (void) testfunc (void)
...@@ -18,12 +18,14 @@ testfunc (void) ...@@ -18,12 +18,14 @@ testfunc (void)
i = 0xFFFFFFFFFFFFFFFF; i = 0xFFFFFFFFFFFFFFFF;
i = 01777777777777777777777; i = 01777777777777777777777;
/* We expect to get either a "width of integer constant changes with /* Nor should values outside the range of (32-bit) unsigned long but
-traditional" warning or an "integer constant is unsigned in ISO inside the range of long long. [since -traditional has no long long,
C, signed with -traditional" warning depending on whether we are we can pretend it worked the way it does in C99.] */
testing on a 32 or 64 bit platform. Either warning means the i = 9223372036854775807;
test passes and both matched by checking for "integer constant". */
i = 18446744073709551615; /* { dg-warning "integer constant" "integer constant" } */ /* But this one should, since it doesn't fit in long (long), but
does fit in unsigned long (long). */
i = 18446744073709551615; /* { dg-warning "decimal constant|unsigned" "decimal constant" } */
# 29 "sys-header.h" 3 # 29 "sys-header.h" 3
/* We are in system headers now, no -Wtraditional warnings should issue. */ /* We are in system headers now, no -Wtraditional warnings should issue. */
...@@ -39,6 +41,3 @@ testfunc (void) ...@@ -39,6 +41,3 @@ testfunc (void)
i = 9223372036854775807; i = 9223372036854775807;
i = 18446744073709551615; i = 18446744073709551615;
} }
/* Ignore "decimal constant is so large that it is unsigned" warnings. */
/* { dg-warning "decimal constant" "decimal constant" { target *-*-* } 26 } */
...@@ -12,13 +12,13 @@ testfunc (void) ...@@ -12,13 +12,13 @@ testfunc (void)
i = 1L; i = 1L;
i = 1l; i = 1l;
i = 1U; /* { dg-warning "traditional C rejects the 'u' suffix" "numeric constant suffix" } */ i = 1U; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
i = 1u; /* { dg-warning "traditional C rejects the 'u' suffix" "numeric constant suffix" } */ i = 1u; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
f = 1.0; f = 1.0;
f = 1.0F; /* { dg-warning "traditional C rejects the 'f' suffix" "numeric constant suffix" } */ f = 1.0F; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
f = 1.0f; /* { dg-warning "traditional C rejects the 'f' suffix" "numeric constant suffix" } */ f = 1.0f; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
f = 1.0L; /* { dg-warning "traditional C rejects the 'l' suffix" "numeric constant suffix" } */ f = 1.0L; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
f = 1.0l; /* { dg-warning "traditional C rejects the 'l' suffix" "numeric constant suffix" } */ f = 1.0l; /* { dg-warning "traditional C rejects" "numeric constant suffix" } */
# 24 "sys-header.h" 3 # 24 "sys-header.h" 3
/* We are in system headers now, no -Wtraditional warnings should issue. */ /* We are in system headers now, no -Wtraditional warnings should issue. */
......
...@@ -2027,7 +2027,9 @@ extern tree global_trees[TI_MAX]; ...@@ -2027,7 +2027,9 @@ extern tree global_trees[TI_MAX];
#define V16SF_type_node global_trees[TI_V16SF_TYPE] #define V16SF_type_node global_trees[TI_V16SF_TYPE]
/* An enumeration of the standard C integer types. These must be /* An enumeration of the standard C integer types. These must be
ordered so that shorter types appear before longer ones. */ ordered so that shorter types appear before longer ones, and so
that signed types appear before unsigned ones, for the correct
functioning of interpret_integer() in c-lex.c. */
enum integer_type_kind enum integer_type_kind
{ {
itk_char, itk_char,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment