]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR63426 Fix various signed integer overflows
authortrippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Nov 2014 16:36:14 +0000 (16:36 +0000)
committertrippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Nov 2014 16:36:14 +0000 (16:36 +0000)
Running the testsuite after bootstrap-ubsan on gcc112 shows several issues. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63426 for the full list.

This patch fixes several of them.

2014-11-20  Markus Trippelsdorf  <markus@trippelsdorf.de>

* config/rs6000/constraints.md: Avoid signed integer overflows.
* config/rs6000/predicates.md: Likewise.
* config/rs6000/rs6000.c (num_insns_constant_wide): Likewise.
(includes_rldic_lshift_p): Likewise.
(includes_rldicr_lshift_p): Likewise.
* emit-rtl.c (const_wide_int_htab_hash): Likewise.
* loop-iv.c (determine_max_iter): Likewise.
(iv_number_of_iterations): Likewise.
* tree-ssa-loop-ivopts.c (get_computation_cost_at): Likewise.
* varasm.c (get_section_anchor): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217886 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/rs6000/constraints.md
gcc/config/rs6000/predicates.md
gcc/config/rs6000/rs6000.c
gcc/emit-rtl.c
gcc/loop-iv.c
gcc/tree-ssa-loop-ivopts.c
gcc/varasm.c

index 3cbdb6f5376ceab07d254d6aecb519d2fd7cb326..5f25791af2dbe58b208dfe8406aea427703bc2c1 100644 (file)
@@ -1,3 +1,16 @@
+2014-11-20  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+       * config/rs6000/constraints.md: Avoid signed integer overflows.
+       * config/rs6000/predicates.md: Likewise.
+       * config/rs6000/rs6000.c (num_insns_constant_wide): Likewise.
+       (includes_rldic_lshift_p): Likewise.
+       (includes_rldicr_lshift_p): Likewise. 
+       * emit-rtl.c (const_wide_int_htab_hash): Likewise.
+       * loop-iv.c (determine_max_iter): Likewise.
+       (iv_number_of_iterations): Likewise.
+       * tree-ssa-loop-ivopts.c (get_computation_cost_at): Likewise.
+       * varasm.c (get_section_anchor): Likewise.
+
 2014-11-20  Charles Baylis  <charles.baylis@linaro.org>
 
        PR target/63870
index 0e0e517d7a1d39a56e89f1d43293046ac261204b..3f12b07e48999bf4c7674165c03d6c1360b1869b 100644 (file)
 (define_constraint "P"
   "constant whose negation is signed 16-bit constant"
   (and (match_code "const_int")
-       (match_test "(unsigned HOST_WIDE_INT) ((- ival) + 0x8000) < 0x10000")))
+       (match_test "((- (unsigned HOST_WIDE_INT) ival) + 0x8000) < 0x10000")))
 
 ;; Floating-point constraints
 
index 1767cbd7a11b97d041de2657f51bcb0ff86ed76d..ea230a5b29a672839c51f86963269c9b0fd3f115 100644 (file)
 (define_predicate "reg_or_sub_cint_operand"
   (if_then_else (match_code "const_int")
     (match_test "(unsigned HOST_WIDE_INT)
-                  (- INTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
+                  (- UINTVAL (op) + (mode == SImode ? 0x80000000 : 0x80008000))
                 < (unsigned HOST_WIDE_INT) 0x100000000ll")
     (match_operand 0 "gpc_reg_operand")))
 
index 506daa1d31e7a03701f76a27faaaa857739c06ea..a9604cf3fa970f9ce8ae6b7a2fba64604982a8cc 100644 (file)
@@ -5083,7 +5083,7 @@ int
 num_insns_constant_wide (HOST_WIDE_INT value)
 {
   /* signed constant loadable with addi */
-  if ((unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000)
+  if (((unsigned HOST_WIDE_INT) value + 0x8000) < 0x10000)
     return 1;
 
   /* constant loadable with addis */
@@ -16194,7 +16194,7 @@ includes_rldic_lshift_p (rtx shiftop, rtx andop)
 {
   if (GET_CODE (andop) == CONST_INT)
     {
-      HOST_WIDE_INT c, lsb, shift_mask;
+      unsigned HOST_WIDE_INT c, lsb, shift_mask;
 
       c = INTVAL (andop);
       if (c == 0 || c == ~0)
@@ -16233,7 +16233,7 @@ includes_rldicr_lshift_p (rtx shiftop, rtx andop)
 {
   if (GET_CODE (andop) == CONST_INT)
     {
-      HOST_WIDE_INT c, lsb, shift_mask;
+      unsigned HOST_WIDE_INT c, lsb, shift_mask;
 
       shift_mask = ~0;
       shift_mask <<= INTVAL (shiftop);
index 1226aad0c137f94f83ee01db5e130f675bb408b5..fa5e41beb463ae04c707ae4dadd2c0199828de84 100644 (file)
@@ -220,7 +220,7 @@ hashval_t
 const_wide_int_hasher::hash (rtx x)
 {
   int i;
-  HOST_WIDE_INT hash = 0;
+  unsigned HOST_WIDE_INT hash = 0;
   const_rtx xr = x;
 
   for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++)
index 8ea458c3fc53c08f066f64ef3360c147017128b0..f55cea2a98595acab12402b9e92a1c02b6d74baa 100644 (file)
@@ -2311,7 +2311,7 @@ determine_max_iter (struct loop *loop, struct niter_desc *desc, rtx old_niter)
     }
 
   get_mode_bounds (desc->mode, desc->signed_p, desc->mode, &mmin, &mmax);
-  nmax = INTVAL (mmax) - INTVAL (mmin);
+  nmax = UINTVAL (mmax) - UINTVAL (mmin);
 
   if (GET_CODE (niter) == UDIV)
     {
@@ -2649,7 +2649,7 @@ iv_number_of_iterations (struct loop *loop, rtx_insn *insn, rtx condition,
          down = INTVAL (CONST_INT_P (iv0.base)
                         ? iv0.base
                         : mode_mmin);
-         max = (up - down) / inc + 1;
+         max = (uint64_t) (up - down) / inc + 1;
          if (!desc->infinite
              && !desc->assumptions)
            record_niter_bound (loop, max, false, true);
index 4007e5483b27725efdeaa3cc6f52d26f5eb16db8..fca18b6cdfe36e74e7c3900492d512b1102875c6 100644 (file)
@@ -4183,7 +4183,7 @@ get_computation_cost_at (struct ivopts_data *data,
 
   if (cst_and_fits_in_hwi (cbase))
     {
-      offset = - ratio * int_cst_value (cbase);
+      offset = - ratio * (unsigned HOST_WIDE_INT) int_cst_value (cbase);
       cost = difference_cost (data,
                              ubase, build_int_cst (utype, 0),
                              &symbol_present, &var_present, &offset,
index 07eb72aee31f268d8a5d69bc605e108e779575e5..99dae5d7098ce281c352b0b3ce59cceb313ab7e7 100644 (file)
@@ -7196,7 +7196,7 @@ get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
     offset = 0;
   else
     {
-      bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
+      bias = HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (ptr_mode) - 1);
       if (offset < 0)
        {
          delta = -(unsigned HOST_WIDE_INT) offset + max_offset;