c-common.c (builtin_define_type_max): Handle unsigned types too.

* c-common.c (builtin_define_type_max): Handle unsigned
	types too.
testsuite:
	* gcc.dg/fshort-wchar: New test.

From-SVN: r60023
This commit is contained in:
Neil Booth 2002-12-11 06:36:17 +00:00 committed by Neil Booth
parent ad1121d10e
commit b3a5a50c26
4 changed files with 51 additions and 27 deletions

View file

@ -1,3 +1,8 @@
2002-12-11 Neil Booth <neil@daikokuya.co.uk>
* c-common.c (builtin_define_type_max): Handle unsigned
types too.
2002-12-10 Janis Johnson <janis187@us.ibm.com>
PR other/8882

View file

@ -5106,8 +5106,9 @@ builtin_define_with_hex_fp_value (macro, type, digits, hex_str, fp_suffix)
cpp_define (parse_in, buf);
}
/* Define MAX for TYPE based on the precision of the type, which is assumed
to be signed. IS_LONG is 1 for type "long" and 2 for "long long". */
/* Define MAX for TYPE based on the precision of the type. IS_LONG is
1 for type "long" and 2 for "long long". We have to handle
unsigned types, since wchar_t might be unsigned. */
static void
builtin_define_type_max (macro, type, is_long)
@ -5115,41 +5116,37 @@ builtin_define_type_max (macro, type, is_long)
tree type;
int is_long;
{
const char *value;
static const char *const values[]
= { "127", "255",
"32767", "65535",
"2147483647", "4294967295",
"9223372036854775807", "18446744073709551615",
"170141183460469231731687303715884105727",
"340282366920938463463374607431768211455" };
static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
const char *value, *suffix;
char *buf;
size_t mlen, vlen, extra;
size_t idx;
/* Pre-rendering the values mean we don't have to futz with printing a
multi-word decimal value. There are also a very limited number of
precisions that we support, so it's really a waste of time. */
switch (TYPE_PRECISION (type))
{
case 8:
value = "127";
break;
case 16:
value = "32767";
break;
case 32:
value = "2147483647";
break;
case 64:
value = "9223372036854775807";
break;
case 128:
value = "170141183460469231731687303715884105727";
break;
default:
abort ();
case 8: idx = 0; break;
case 16: idx = 2; break;
case 32: idx = 4; break;
case 64: idx = 6; break;
case 128: idx = 8; break;
default: abort ();
}
mlen = strlen (macro);
vlen = strlen (value);
extra = 2 + is_long;
buf = alloca (mlen + vlen + extra);
value = values[idx + TREE_UNSIGNED (type)];
suffix = suffixes[is_long * 2 + TREE_UNSIGNED (type)];
sprintf (buf, "%s=%s%s", macro, value,
(is_long == 1 ? "L" : is_long == 2 ? "LL" : ""));
buf = alloca (strlen (macro) + 1 + strlen (value) + strlen (suffix) + 1);
sprintf (buf, "%s=%s%s", macro, value, suffix);
cpp_define (parse_in, buf);
}

View file

@ -1,3 +1,7 @@
2002-12-11 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/fshort-wchar: New test.
2002-12-10 Mark Mitchell <mark@codesourcery.com>
PR c++/8372

View file

@ -0,0 +1,18 @@
/* Copyright (C) 2002 Free Software Foundation, Inc. */
/* { dg-do run } */
/* { dg-options "-fshort-wchar" } */
/* Source: Neil Booth, 10 Dec 2002.
Test that __WCHAR_MAX__ is correct with -fshort-wchar. */
int main ()
{
__WCHAR_TYPE__ w = ~(__WCHAR_TYPE__) 0;
if (w != __WCHAR_MAX__)
abort ();
return 0;
}