Commit c9220e3a by Neil Booth Committed by Neil Booth

c-common.c (c_common_init): Set CPP arithmetic precision.

	* c-common.c (c_common_init): Set CPP arithmetic precision.
	* cppexp.c (cpp_num_part): Move typedef ...
	* cpphash.h: ...here; make unsigned HOST_WIDE_INT.
	* cppinit.c (cpp_create_reader): Default to host long arithmetic.
	(sanity_checks): Update.
testsuite:
	* gcc.dg/cpp/arith-2.c, gcc.dg/cpp/arith-3.c: New tests.
	* gcc.dg/cpp/if-3.c: Remove.

From-SVN: r53911
parent 1457a0b5
2002-05-27 Neil Booth <neil@daikokuya.demon.co.uk>
* c-common.c (c_common_init): Set CPP arithmetic precision.
* cppexp.c (cpp_num_part): Move typedef ...
* cpphash.h: ...here; make unsigned HOST_WIDE_INT.
* cppinit.c (cpp_create_reader): Default to host long arithmetic.
(sanity_checks): Update.
2002-05-26 Geoffrey Keating <geoffk@redhat.com> 2002-05-26 Geoffrey Keating <geoffk@redhat.com>
* Makefile.in (INSTALL_HEADERS): Add 'install-mkheaders'. * Makefile.in (INSTALL_HEADERS): Add 'install-mkheaders'.
......
...@@ -4488,6 +4488,10 @@ c_common_init (filename) ...@@ -4488,6 +4488,10 @@ c_common_init (filename)
/* Set up preprocessor arithmetic. Must be done after call to /* Set up preprocessor arithmetic. Must be done after call to
c_common_nodes_and_builtins for wchar_type_node to be good. */ c_common_nodes_and_builtins for wchar_type_node to be good. */
if (flag_isoc99)
options->precision = TYPE_PRECISION (intmax_type_node);
else
options->precision = TYPE_PRECISION (long_integer_type_node);
options->char_precision = TYPE_PRECISION (char_type_node); options->char_precision = TYPE_PRECISION (char_type_node);
options->int_precision = TYPE_PRECISION (integer_type_node); options->int_precision = TYPE_PRECISION (integer_type_node);
options->wchar_precision = TYPE_PRECISION (wchar_type_node); options->wchar_precision = TYPE_PRECISION (wchar_type_node);
......
...@@ -23,7 +23,6 @@ Boston, MA 02111-1307, USA. */ ...@@ -23,7 +23,6 @@ Boston, MA 02111-1307, USA. */
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
typedef unsigned long cpp_num_part;
typedef struct cpp_num cpp_num; typedef struct cpp_num cpp_num;
#define PART_PRECISION (sizeof (cpp_num_part) * CHAR_BIT) #define PART_PRECISION (sizeof (cpp_num_part) * CHAR_BIT)
......
...@@ -29,6 +29,7 @@ struct directive; /* Deliberately incomplete. */ ...@@ -29,6 +29,7 @@ struct directive; /* Deliberately incomplete. */
struct pending_option; struct pending_option;
struct op; struct op;
typedef unsigned HOST_WIDE_INT cpp_num_part;
typedef unsigned char uchar; typedef unsigned char uchar;
#define U (const uchar *) /* Intended use: U"string" */ #define U (const uchar *) /* Intended use: U"string" */
......
...@@ -496,8 +496,7 @@ cpp_create_reader (lang) ...@@ -496,8 +496,7 @@ cpp_create_reader (lang)
/* Default CPP arithmetic to something sensible for the host for the /* Default CPP arithmetic to something sensible for the host for the
benefit of dumb users like fix-header. */ benefit of dumb users like fix-header. */
#define BITS_PER_HOST_WIDEST_INT (CHAR_BIT * sizeof (HOST_WIDEST_INT)) CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long);
CPP_OPTION (pfile, precision) = BITS_PER_HOST_WIDEST_INT;
CPP_OPTION (pfile, char_precision) = CHAR_BIT; CPP_OPTION (pfile, char_precision) = CHAR_BIT;
CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int);
CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
...@@ -848,6 +847,7 @@ static void sanity_checks (pfile) ...@@ -848,6 +847,7 @@ static void sanity_checks (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cppchar_t test = 0; cppchar_t test = 0;
size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part);
/* Sanity checks for assumptions about CPP arithmetic and target /* Sanity checks for assumptions about CPP arithmetic and target
type precisions made by cpplib. */ type precisions made by cpplib. */
...@@ -855,11 +855,11 @@ static void sanity_checks (pfile) ...@@ -855,11 +855,11 @@ static void sanity_checks (pfile)
if (test < 1) if (test < 1)
cpp_error (pfile, DL_ICE, "cppchar_t must be an unsigned type"); cpp_error (pfile, DL_ICE, "cppchar_t must be an unsigned type");
if (CPP_OPTION (pfile, precision) > BITS_PER_HOST_WIDEST_INT) if (CPP_OPTION (pfile, precision) > max_precision)
cpp_error (pfile, DL_ICE, cpp_error (pfile, DL_ICE,
"preprocessor arithmetic has maximum precision of %lu bits; target requires %lu bits", "preprocessor arithmetic has maximum precision of %lu bits; target requires %lu bits",
(unsigned long)BITS_PER_HOST_WIDEST_INT, (unsigned long) max_precision,
(unsigned long)CPP_OPTION (pfile, precision)); (unsigned long) CPP_OPTION (pfile, precision));
if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision)) if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision))
cpp_error (pfile, DL_ICE, cpp_error (pfile, DL_ICE,
...@@ -876,11 +876,15 @@ static void sanity_checks (pfile) ...@@ -876,11 +876,15 @@ static void sanity_checks (pfile)
cpp_error (pfile, DL_ICE, cpp_error (pfile, DL_ICE,
"target int is narrower than target char"); "target int is narrower than target char");
/* This is assumed in eval_token() and could be fixed if necessary. */
if (sizeof (cppchar_t) > sizeof (cpp_num_part))
cpp_error (pfile, DL_ICE, "CPP half-integer narrower than CPP character");
if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T) if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
cpp_error (pfile, DL_ICE, cpp_error (pfile, DL_ICE,
"CPP on this host cannot handle wide character constants over %lu bits, but the target requires %lu bits", "CPP on this host cannot handle wide character constants over %lu bits, but the target requires %lu bits",
(unsigned long)BITS_PER_CPPCHAR_T, (unsigned long) BITS_PER_CPPCHAR_T,
(unsigned long)CPP_OPTION (pfile, wchar_precision)); (unsigned long) CPP_OPTION (pfile, wchar_precision));
} }
#else #else
# define sanity_checks(PFILE) # define sanity_checks(PFILE)
......
2002-05-27 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.dg/cpp/arith-2.c, gcc.dg/cpp/arith-3.c: New tests.
* gcc.dg/cpp/if-3.c: Remove.
2002-05-26 Jakub Jelinek <jakub@redhat.com> 2002-05-26 Jakub Jelinek <jakub@redhat.com>
* g++.dg/opt/cse2.C: New test. * g++.dg/opt/cse2.C: New test.
......
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