[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] Fix UBSAN error, shifting 64 bit value by 64.

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:48:54 GMT 2020


https://gcc.gnu.org/g:50c96067c8ed60f4b3fcbee89fe31c905241b356

commit 50c96067c8ed60f4b3fcbee89fe31c905241b356
Author: Aaron Sawdey <acsawdey@linux.ibm.com>
Date:   Fri Mar 13 18:14:22 2020 -0500

    Fix UBSAN error, shifting 64 bit value by 64.
    
    2020-03-13  Aaron Sawdey  <acsawdey@linux.ibm.com>
    
            PR target/92379
            * config/rs6000/rs6000.c (num_insns_constant_multi) Don't shift a
            64-bit value by 64 bits (UB).

Diff:
---
 gcc/ChangeLog              | 6 ++++++
 gcc/config/rs6000/rs6000.c | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4ea81e6c404..2daa351088d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-13  Aaron Sawdey  <acsawdey@linux.ibm.com>
+
+	PR target/92379
+	* config/rs6000/rs6000.c (num_insns_constant_multi) Don't shift a
+	64-bit value by 64 bits (UB).
+
 2020-03-13  Vladimir Makarov  <vmakarov@redhat.com>
 
 	PR rtl-optimization/92303
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 24598aff663..5798f924472 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -5612,7 +5612,10 @@ num_insns_constant_multi (HOST_WIDE_INT value, machine_mode mode)
 	  && rs6000_is_valid_and_mask (GEN_INT (low), DImode))
 	insns = 2;
       total += insns;
-      value >>= BITS_PER_WORD;
+      /* If BITS_PER_WORD is the number of bits in HOST_WIDE_INT, doing
+	 it all at once would be UB. */
+      value >>= (BITS_PER_WORD - 1);
+      value >>= 1;
     }
   return total;
 }


More information about the Gcc-cvs mailing list