aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.co.uk>2002-12-11 06:36:17 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-12-11 06:36:17 +0000
commitb3a5a50c2654771597c96da1b82164623ab7adef (patch)
tree2adc3a801640347ac864e1920661c16bf1aba14b /gcc/c-common.c
parentad1121d10ea102d3f193413a4c80e3b48a4ecec2 (diff)
downloadgcc-b3a5a50c2654771597c96da1b82164623ab7adef.zip
gcc-b3a5a50c2654771597c96da1b82164623ab7adef.tar.gz
gcc-b3a5a50c2654771597c96da1b82164623ab7adef.tar.bz2
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
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 35adf76..76f7927 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);
}