From 13c457e1923eefa04f4b52e5321ef6e2379d6a8b Mon Sep 17 00:00:00 2001 From: neil Date: Sat, 4 May 2002 07:30:32 +0000 Subject: * c-lex.c (lex_string): Let cpp_parse_escape handles truncation and sign-extension. (lex_charconst): Update for change in prototype of cpp_interpret_charconst. Extend from cppchar_t to HOST_WIDE_INT appropriately. * cpphash.h (BITS_PER_CPPCHAR_T): New. * cppinit.c (cpp_create_reader): Initialize them for no change in semantics. (cpp_post_options): Add sanity checks. * cpplex.c (cpp_parse_escape): Handle precision, sign-extension and truncation issues. Calculate in type cppchar_t. (MAX_CHAR_TYPE_SIZE, MAX_WCHAR_TYPE_SIZE): Remove. (cpp_interpret_charconst): Calculate in type cppchar_t. Handle run-time dependent precision correctly. Return whether the result is signed or not. * cpplib.c (dequote_string): Use cppchar_t; update. * cpplib.h (cppchar_signed_t): New. struct cpp_options): New precision members. (cpp_interpret_charconst, cpp_parse_escape): Update prototypes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53152 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cppinit.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gcc/cppinit.c') diff --git a/gcc/cppinit.c b/gcc/cppinit.c index cee75713447..cb5b263151b 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -502,6 +502,18 @@ cpp_create_reader (lang) CPP_OPTION (pfile, pending) = (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); + /* CPP arithmetic done to existing rules for now. */ +#define BITS_PER_HOST_WIDEST_INT (CHAR_BIT * sizeof (HOST_WIDEST_INT)) + CPP_OPTION (pfile, precision) = BITS_PER_HOST_WIDEST_INT; +#ifndef MAX_CHAR_TYPE_SIZE +#define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE +#endif + CPP_OPTION (pfile, char_precision) = MAX_CHAR_TYPE_SIZE; +#ifndef MAX_WCHAR_TYPE_SIZE +#define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE +#endif + CPP_OPTION (pfile, wchar_precision) = MAX_WCHAR_TYPE_SIZE; + /* It's simplest to just create this struct whether or not it will be needed. */ pfile->deps = deps_init (); @@ -1796,6 +1808,27 @@ cpp_post_options (pfile) fputc ('\n', stderr); } +#if ENABLE_CHECKING + /* Sanity checks for CPP arithmetic. */ + if (CPP_OPTION (pfile, precision) > BITS_PER_HOST_WIDEST_INT) + cpp_error (pfile, DL_FATAL, + "preprocessor arithmetic has maximum precision of %u bits; target requires %u bits", + BITS_PER_HOST_WIDEST_INT, CPP_OPTION (pfile, precision)); + + if (CPP_OPTION (pfile, char_precision) > BITS_PER_CPPCHAR_T + || CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T) + cpp_error (pfile, DL_FATAL, + "CPP cannot handle (wide) character constants over %u bits", + BITS_PER_CPPCHAR_T); + + { + cppchar_t test = 0; + test--; + if (test < 1) + cpp_error (pfile, DL_FATAL, "cppchar_t must be an unsigned type"); + } +#endif + /* Canonicalize in_fname and out_fname. We guarantee they are not NULL, and that the empty string represents stdin / stdout. */ if (CPP_OPTION (pfile, in_fname) == NULL -- cgit v1.2.3