This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR78588 - rtlanal.c:5210:38: runtime error: shift exponent 4294967295 is too large for 64-bit type
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Markus Trippelsdorf <markus at trippelsdorf dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Nov 2016 15:14:15 +0100
- Subject: Re: [PATCH] Fix PR78588 - rtlanal.c:5210:38: runtime error: shift exponent 4294967295 is too large for 64-bit type
- Authentication-results: sourceware.org; auth=none
- References: <20161129140815.GA441@x4>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Nov 29, 2016 at 03:08:15PM +0100, Markus Trippelsdorf wrote:
> Building gcc with -fsanitize=undefined shows:
> rtlanal.c:5210:38: runtime error: shift exponent 4294967295 is too
> large for 64-bit type 'long unsigned int'
>
> 5210 return nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))
> 5211 ? 1 : bitwidth - floor_log2 (nonzero) - 1;
>
> Here (bitwidth - 1) wraps around because bitwidth is zero and unsigned.
Which modes have precision of 0? I'd expect just VOIDmode and BLKmode, any
others? And for those I'd say it is a bug to call num_sign_bit_copies*.
> Tested on ppc64le.
> OK for trunk?
>
> Thanks.
>
> * rtlanal.c (num_sign_bit_copies1): Check for zero bitwidth.
>
> diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
> index 4e4eb2ef3458..918088a0db8e 100644
> --- a/gcc/rtlanal.c
> +++ b/gcc/rtlanal.c
> @@ -5203,7 +5203,7 @@ num_sign_bit_copies1 (const_rtx x, machine_mode mode, const_rtx known_x,
> safely compute the mask for this mode, always return BITWIDTH. */
>
> bitwidth = GET_MODE_PRECISION (mode);
> - if (bitwidth > HOST_BITS_PER_WIDE_INT)
> + if (bitwidth == 0 || bitwidth > HOST_BITS_PER_WIDE_INT)
> return 1;
>
> nonzero = nonzero_bits (x, mode);
>
> --
> Markus
Jakub