From b5f6893d0e63ae4b60ef902e558ced3c71edd5b4 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 11 Dec 2002 06:36:17 +0000 Subject: * c-common.c (builtin_define_type_max): Handle unsigned types too. testsuite: * gcc.dg/fshort-wchar: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@60023 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 ++++ gcc/c-common.c | 51 +++++++++++++++++-------------------- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/fshort-wchar.c | 18 +++++++++++++ 4 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fshort-wchar.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d46e2df05fe..3e0756a638a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2002-12-11 Neil Booth + + * c-common.c (builtin_define_type_max): Handle unsigned + types too. + 2002-12-10 Janis Johnson PR other/8882 diff --git a/gcc/c-common.c b/gcc/c-common.c index 35adf760020..76f79274861 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f54e347f5f2..f00da68cfc9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-12-11 Neil Booth + + * gcc.dg/fshort-wchar: New test. + 2002-12-10 Mark Mitchell PR c++/8372 diff --git a/gcc/testsuite/gcc.dg/fshort-wchar.c b/gcc/testsuite/gcc.dg/fshort-wchar.c new file mode 100644 index 00000000000..074e872358b --- /dev/null +++ b/gcc/testsuite/gcc.dg/fshort-wchar.c @@ -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; +} -- cgit v1.2.3