This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Avoid printing host INT_MIN as raw digits
- From: "Zack Weinberg" <zack at codesourcery dot com>
- To: tm <tm at kloo dot net>
- Cc: Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 19 Dec 2003 10:13:59 -0800
- Subject: Re: [PATCH] Avoid printing host INT_MIN as raw digits
- References: <Pine.LNX.4.21.0312181413290.20602-100000@mail.kloo.net>
tm <tm@kloo.net> writes:
>> Not the prettiest. I committed this version instead.
> ...
>> + static void
>> + print_host_wide_int (HOST_WIDE_INT val)
>> + {
>> + HOST_WIDE_INT min = (unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT-1);
>> + if (val == min)
>> + printf ("(" HOST_WIDE_INT_PRINT_DEC_C "-1)", val + 1);
>> + else
>> + printf (HOST_WIDE_INT_PRINT_DEC_C, val);
>> + }
> ...
>
> I originally wrote something similar to that, but Zack insisted it be
> implemented differently so it will work properly when configured for a
> Canadian cross on a 32-bit build machine to a 64-bit host machine.
I haven't seen the rest of the thread yet, but yeah. The problem case
for this code is the other way round: 64-bit build machine, 32-bit
host. Then if the value is -(2**31), this code will not detect it as
a problem (because HOST_WIDE_INT on the *build* machine is 64 bits, so
it only considers -(2**63) to be a problem) but the emitted constant
will still hit the problem case when it's compiled for the *host*,
with 32-bit HOST_WIDE_INT.
Note also that you're printing the _build machine_'s HOST_WIDE_INT
suffix on the constant, which may be wrong for the host.
zw