HOST_WIDE_INT, preprocessing, and MIPS
Mark Mitchell
mark@markmitchell.com
Fri Dec 18 18:41:00 GMT 1998
Folks --
On 64-bit mips the preprocessor turns out to be quite severely
broken. In particular, the following program:
#if (1L << 32)
x
#endif
yields:
> g++ -mabi=64 -E test.c
# 1 "test.c"
after preprocessing. But, since a long is 64-bits in this
environment, this should not occur.
The problem is that cccp.c uses HOST_WIDE_INT to do computations,
and mips.h defines this to long, and cccp.c is compiled using the
32-bit object model, in which long is just 32-bits.
One possibility is to make HOST_WIDE_INT wider than 32-bits. But, I
bet this will cause problems in lots of places.
In cccp.c, we have:
#ifndef HOST_WIDE_INT
# if HAVE_INTTYPES_H
# include <inttypes.h>
# define HOST_WIDE_INT intmax_t
# else
# if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)
# define HOST_WIDE_INT int
# else
# if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG || ! (defined LONG_LONG_MAX || defined LLONG_MAX))
# define HOST_WIDE_INT long
# else
# define HOST_WIDE_INT long long
# endif
# endif
# endif
#endif
The problem is that HOST_WIDE_INT is being defined in mips.h,
included via config.h, which causes us not to use intmax_t here.
Apparently this is done to provide return types for some functions
declared in mips.h.
I suggest that we rename the definitions in mips.h to
MIPS_HOST_WIDE_INT, or some such, so that this breakage does not
occur. That would allow the HAVE_INTTYPES_H test to fire.
Alternatively, we could reorder the cccp.c tests to give
HAVE_INTTYPES_H priority.
Also, there was discussion recently about removing the use of
inttypes.h from the definition of HOST_WIDE_INT. I think this
examples shows that it *must* be present. Since the preprocessor
doesn't know about the object model, it must use the widest type
available on the platform, period.
Jim, I would like to make the change I suggest to mips.h. (Namely,
to rename HOST_WIDE_INT to MIPS_HOST_WIDE_INT.) OK?
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
More information about the Gcc-bugs
mailing list