public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR78588 - rtlanal.c:5210:38: runtime error: shift exponent 4294967295 is too large for 64-bit type
@ 2016-11-29 14:08 Markus Trippelsdorf
  2016-11-29 14:14 ` Jakub Jelinek
  2016-11-29 16:00 ` [PATCH v2] " Markus Trippelsdorf
  0 siblings, 2 replies; 8+ messages in thread
From: Markus Trippelsdorf @ 2016-11-29 14:08 UTC (permalink / raw)
  To: gcc-patches

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. 

Fix by returning earlier if bitwidth is zero.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-11-30  7:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29 14:08 [PATCH] Fix PR78588 - rtlanal.c:5210:38: runtime error: shift exponent 4294967295 is too large for 64-bit type Markus Trippelsdorf
2016-11-29 14:14 ` Jakub Jelinek
2016-11-29 14:21   ` Markus Trippelsdorf
2016-11-29 15:01     ` Markus Trippelsdorf
2016-11-29 15:07       ` Markus Trippelsdorf
2016-11-29 16:00 ` [PATCH v2] " Markus Trippelsdorf
2016-11-29 21:25   ` Segher Boessenkool
2016-11-30  7:34     ` Markus Trippelsdorf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).