]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR other/59545 (Signed integer overflow issues)
authorJakub Jelinek <jakub@redhat.com>
Thu, 19 Dec 2013 21:27:51 +0000 (22:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 19 Dec 2013 21:27:51 +0000 (22:27 +0100)
PR other/59545
* genattrtab.c (struct attr_hash): Change hashcode type to unsigned.
(attr_hash_add_rtx, attr_hash_add_string): Change hashcode parameter
to unsigned.
(attr_rtx_1): Change hashcode variable to unsigned.
(attr_string): Likewise.  Perform first multiplication in unsigned
type.
* ifcvt.c (noce_try_store_flag_constants): Avoid signed integer
overflows.
* double-int.c (neg_double): Likewise.
* stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
* combine.c (force_to_mode): Likewise.
* postreload.c (move2add_use_add2_insn, move2add_use_add3_insn,
reload_cse_move2add, move2add_note_store): Likewise.
* simplify-rtx.c (simplify_const_unary_operation,
simplify_const_binary_operation): Likewise.
* ipa-split.c (find_split_points): Initialize first.can_split
and first.non_ssa_vars.
* gengtype-state.c (read_state_files_list): Fix up check.
* genautomata.c (reserv_sets_hash_value): Use portable rotation
idiom.
java/
* class.c (hashUtf8String): Compute hash in unsigned type.
* javaop.h (WORD_TO_INT): Avoid signed integer overflow.

From-SVN: r206134

14 files changed:
gcc/ChangeLog
gcc/combine.c
gcc/double-int.c
gcc/genattrtab.c
gcc/genautomata.c
gcc/gengtype-state.c
gcc/ifcvt.c
gcc/ipa-split.c
gcc/java/ChangeLog
gcc/java/class.c
gcc/java/javaop.h
gcc/postreload.c
gcc/simplify-rtx.c
gcc/stor-layout.c

index bc32092b8cd2231caeecb0af4ddc0efd43aefddf..c2cc196d82daae71801710551bb5150cbb8b3ccf 100644 (file)
@@ -1,3 +1,27 @@
+2013-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR other/59545
+       * genattrtab.c (struct attr_hash): Change hashcode type to unsigned.
+       (attr_hash_add_rtx, attr_hash_add_string): Change hashcode parameter
+       to unsigned.
+       (attr_rtx_1): Change hashcode variable to unsigned.
+       (attr_string): Likewise.  Perform first multiplication in unsigned
+       type.
+       * ifcvt.c (noce_try_store_flag_constants): Avoid signed integer
+       overflows.
+       * double-int.c (neg_double): Likewise.
+       * stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
+       * combine.c (force_to_mode): Likewise.
+       * postreload.c (move2add_use_add2_insn, move2add_use_add3_insn,
+       reload_cse_move2add, move2add_note_store): Likewise.
+       * simplify-rtx.c (simplify_const_unary_operation,
+       simplify_const_binary_operation): Likewise.
+       * ipa-split.c (find_split_points): Initialize first.can_split
+       and first.non_ssa_vars.
+       * gengtype-state.c (read_state_files_list): Fix up check.
+       * genautomata.c (reserv_sets_hash_value): Use portable rotation
+       idiom.
+
 2013-12-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * config/arm/neon-docgen.ml: Add crypto intrinsics documentation.
index dea6c2818bb7a6e3cb89c0259bae17cc042aa0c6..ed1dac9d0534a0262839e0ab7d86fcafe98c6332 100644 (file)
@@ -8200,9 +8200,7 @@ force_to_mode (rtx x, enum machine_mode mode, unsigned HOST_WIDE_INT mask,
       /* If X is (minus C Y) where C's least set bit is larger than any bit
         in the mask, then we may replace with (neg Y).  */
       if (CONST_INT_P (XEXP (x, 0))
-         && (((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 0))
-                                       & -INTVAL (XEXP (x, 0))))
-             > mask))
+         && ((UINTVAL (XEXP (x, 0)) & -UINTVAL (XEXP (x, 0))) > mask))
        {
          x = simplify_gen_unary (NEG, GET_MODE (x), XEXP (x, 1),
                                  GET_MODE (x));
index 3803a63e3a9af51084e54e6a972f9269ddcb069e..a810a050e5779ee7be9bce8a87d7b89e95e4abb6 100644 (file)
@@ -138,7 +138,7 @@ neg_double (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
   if (l1 == 0)
     {
       *lv = 0;
-      *hv = - h1;
+      *hv = - (unsigned HOST_WIDE_INT) h1;
       return (*hv & h1) < 0;
     }
   else
index c0125d103b71495b4fef6f0b85e809790a2b3572..70f35316404823cd4314537e037709a8d2d0200f 100644 (file)
@@ -320,7 +320,7 @@ static FILE *attr_file, *dfa_file, *latency_file;
 struct attr_hash
 {
   struct attr_hash *next;      /* Next structure in the bucket.  */
-  int hashcode;                        /* Hash code of this rtx or string.  */
+  unsigned int hashcode;       /* Hash code of this rtx or string.  */
   union
     {
       char *str;               /* The string (negative hash codes) */
@@ -345,7 +345,7 @@ static struct attr_hash *attr_hash_table[RTL_HASH_SIZE];
 /* Add an entry to the hash table for RTL with hash code HASHCODE.  */
 
 static void
-attr_hash_add_rtx (int hashcode, rtx rtl)
+attr_hash_add_rtx (unsigned int hashcode, rtx rtl)
 {
   struct attr_hash *h;
 
@@ -359,7 +359,7 @@ attr_hash_add_rtx (int hashcode, rtx rtl)
 /* Add an entry to the hash table for STRING with hash code HASHCODE.  */
 
 static void
-attr_hash_add_string (int hashcode, char *str)
+attr_hash_add_string (unsigned int hashcode, char *str)
 {
   struct attr_hash *h;
 
@@ -384,7 +384,7 @@ static rtx
 attr_rtx_1 (enum rtx_code code, va_list p)
 {
   rtx rt_val = NULL_RTX;/* RTX to return to caller...          */
-  int hashcode;
+  unsigned int hashcode;
   struct attr_hash *h;
   struct obstack *old_obstack = rtl_obstack;
 
@@ -612,15 +612,15 @@ static char *
 attr_string (const char *str, int len)
 {
   struct attr_hash *h;
-  int hashcode;
+  unsigned int hashcode;
   int i;
   char *new_str;
 
   /* Compute the hash code.  */
-  hashcode = (len + 1) * 613 + (unsigned) str[0];
+  hashcode = (len + 1) * 613U + (unsigned) str[0];
   for (i = 1; i < len; i += 2)
     hashcode = ((hashcode * 613) + (unsigned) str[i]);
-  if (hashcode < 0)
+  if ((int) hashcode < 0)
     hashcode = -hashcode;
 
   /* Search the table for the string.  */
index 5580c69a352dd87ffa685d873aba427c0206b098..372ba90efc8d30dc7efff37fcab5dc5f6a0a12df 100644 (file)
@@ -3494,7 +3494,7 @@ reserv_sets_hash_value (reserv_sets_t reservs)
     {
       reservs_num--;
       hash_value += ((*reserv_ptr >> i)
-                    | (*reserv_ptr << (sizeof (set_el_t) * CHAR_BIT - i)));
+                    | (*reserv_ptr << ((sizeof (set_el_t) * CHAR_BIT) & -i)));
       i++;
       if (i == sizeof (set_el_t) * CHAR_BIT)
        i = 0;
index fda473a2dbe5e5774806a18598c0f516516b8cad..ef7713ff06a0beedd97933054b293366500008e9 100644 (file)
@@ -2651,7 +2651,7 @@ read_state_files_list (void)
                                 "expecting file in !fileslist of state file");
        };
       t0 = peek_state_token (0);
-      if (!state_token_kind (t0) == STOK_RIGHTPAR)
+      if (state_token_kind (t0) != STOK_RIGHTPAR)
        fatal_reading_state (t0, "missing ) for !fileslist in state file");
       next_state_tokens (1);
     }
index 569b9bf46c4fbdac9914f9cf5084b5dc75b84543..db5b8a23eb84c32d2d19e2c547b16045ccbfab92 100644 (file)
@@ -1112,12 +1112,13 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
       ifalse = INTVAL (if_info->a);
       itrue = INTVAL (if_info->b);
 
+      diff = (unsigned HOST_WIDE_INT) itrue - ifalse;
       /* Make sure we can represent the difference between the two values.  */
-      if ((itrue - ifalse > 0)
+      if ((diff > 0)
          != ((ifalse < 0) != (itrue < 0) ? ifalse < 0 : ifalse < itrue))
        return FALSE;
 
-      diff = trunc_int_for_mode (itrue - ifalse, mode);
+      diff = trunc_int_for_mode (diff, mode);
 
       can_reverse = (reversed_comparison_code (if_info->cond, if_info->jump)
                     != UNKNOWN);
@@ -1148,7 +1149,7 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
       if (reversep)
        {
          tmp = itrue; itrue = ifalse; ifalse = tmp;
-         diff = trunc_int_for_mode (-diff, mode);
+         diff = trunc_int_for_mode (-(unsigned HOST_WIDE_INT) diff, mode);
        }
 
       start_sequence ();
index 43758b6db7ae36ef4a22f358180b26d14e38a269..40c8fd6f99b21c9f1ad94a475c8b7004bb598e71 100644 (file)
@@ -950,7 +950,9 @@ find_split_points (int overall_time, int overall_size)
   first.earliest = INT_MAX;
   first.set_ssa_names = 0;
   first.used_ssa_names = 0;
+  first.non_ssa_vars = 0;
   first.bbs_visited = 0;
+  first.can_split = false;
   stack.safe_push (first);
   ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = (void *)(intptr_t)-1;
 
index 3b8a95a6baf12c79f7a163b39d98221ef21bbbac..5ab19210cb7258028dc0a47aebbf88cec6ecda7a 100644 (file)
@@ -1,3 +1,9 @@
+2013-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR other/59545
+       * class.c (hashUtf8String): Compute hash in unsigned type.
+       * javaop.h (WORD_TO_INT): Avoid signed integer overflow.
+
 2013-11-22  Andrew MacLeod  <amacleod@redhat.com>
 
        * java-gimplify.c: Add required include files from gimple.h.
index 532c9c1d94f5197adb084efee781ee20f5d84103..e5d2e6d8e8c47473d37039fbec7538a7f38c7d4e 100644 (file)
@@ -920,7 +920,7 @@ hashUtf8String (const char *str, int len)
 {
   const unsigned char* ptr = (const unsigned char*) str;
   const unsigned char *limit = ptr + len;
-  int32 hash = 0;
+  uint32 hash = 0;
   for (; ptr < limit;)
     {
       int ch = UTF8_GET (ptr, limit);
index 574c10c79928398ac35236121acd5ec80693ff99..bffa857cc3ebdc1169a8b50d35a26f6456d73d89 100644 (file)
@@ -154,7 +154,7 @@ WORD_TO_INT(jword w)
 {
   jint n = w & 0xffffffff; /* Mask lower 32 bits.  */
   n ^= (jint)1 << 31;
-  n -= (jint)1 << 31; /* Sign extend lower 32 bits to upper.  */
+  n -= (uint32)1 << 31; /* Sign extend lower 32 bits to upper.  */
   return n;
 } 
 
index 37bd9ff6ae38668caed601be87809853dfc7a2c8..478a552608f73db6f1cc3e07dda2aa527fb521fd 100644 (file)
@@ -1766,7 +1766,7 @@ move2add_use_add2_insn (rtx reg, rtx sym, rtx off, rtx insn)
   rtx pat = PATTERN (insn);
   rtx src = SET_SRC (pat);
   int regno = REGNO (reg);
-  rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[regno],
+  rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[regno],
                              GET_MODE (reg));
   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
   bool changed = false;
@@ -1866,7 +1866,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
        && reg_symbol_ref[i] != NULL_RTX
        && rtx_equal_p (sym, reg_symbol_ref[i]))
       {
-       rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[i],
+       rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[i],
                                    GET_MODE (reg));
        /* (set (reg) (plus (reg) (const_int 0))) is not canonical;
           use (set (reg) (reg)) instead.
@@ -1901,7 +1901,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
       tem = gen_rtx_REG (GET_MODE (reg), min_regno);
       if (i != min_regno)
        {
-         rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[min_regno],
+         rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[min_regno],
                                      GET_MODE (reg));
          tem = gen_rtx_PLUS (GET_MODE (reg), tem, new_src);
        }
@@ -2010,7 +2010,7 @@ reload_cse_move2add (rtx first)
                      && CONST_INT_P (XEXP (SET_SRC (set), 1)))
                    {
                      rtx src3 = XEXP (SET_SRC (set), 1);
-                     HOST_WIDE_INT added_offset = INTVAL (src3);
+                     unsigned HOST_WIDE_INT added_offset = UINTVAL (src3);
                      HOST_WIDE_INT base_offset = reg_offset[REGNO (src)];
                      HOST_WIDE_INT regno_offset = reg_offset[regno];
                      rtx new_src =
@@ -2224,7 +2224,7 @@ move2add_note_store (rtx dst, const_rtx set, void *data)
     {
       rtx src = SET_SRC (set);
       rtx base_reg;
-      HOST_WIDE_INT offset;
+      unsigned HOST_WIDE_INT offset;
       int base_regno;
 
       switch (GET_CODE (src))
@@ -2235,7 +2235,7 @@ move2add_note_store (rtx dst, const_rtx set, void *data)
              base_reg = XEXP (src, 0);
 
              if (CONST_INT_P (XEXP (src, 1)))
-               offset = INTVAL (XEXP (src, 1));
+               offset = UINTVAL (XEXP (src, 1));
              else if (REG_P (XEXP (src, 1))
                       && move2add_valid_value_p (REGNO (XEXP (src, 1)), mode))
                {
index 78cd665e9a858800dd4a5ec08a587b249f73dcf2..3019fd86112dd7d1a99e136a2df31909b2542e2f 100644 (file)
@@ -1647,7 +1647,7 @@ simplify_const_unary_operation (enum rtx_code code, enum machine_mode mode,
          break;
 
        case NEG:
-         val = - arg0;
+         val = - (unsigned HOST_WIDE_INT) arg0;
          break;
 
        case ABS:
@@ -4117,15 +4117,15 @@ simplify_const_binary_operation (enum rtx_code code, enum machine_mode mode,
       switch (code)
        {
        case PLUS:
-         val = arg0s + arg1s;
+         val = (unsigned HOST_WIDE_INT) arg0s + arg1s;
          break;
 
        case MINUS:
-         val = arg0s - arg1s;
+         val = (unsigned HOST_WIDE_INT) arg0s - arg1s;
          break;
 
        case MULT:
-         val = arg0s * arg1s;
+         val = (unsigned HOST_WIDE_INT) arg0s * arg1s;
          break;
 
        case DIV:
index 9325525dd9fd86c368c6184db8eaf7d2d341a0ed..675a12386eba59495789f4d4981a3e5dc05bd6e0 100644 (file)
@@ -2521,7 +2521,7 @@ set_min_and_max_values_for_integral_type (tree type,
       max_value
        = build_int_cst_wide (type, precision - HOST_BITS_PER_WIDE_INT >= 0
                              ? -1
-                             : ((HOST_WIDE_INT) 1 << precision) - 1,
+                             : (HOST_WIDE_INT_1U << precision) - 1,
                              precision - HOST_BITS_PER_WIDE_INT > 0
                              ? ((unsigned HOST_WIDE_INT) ~0
                                 >> (HOST_BITS_PER_WIDE_INT
@@ -2534,7 +2534,7 @@ set_min_and_max_values_for_integral_type (tree type,
        = build_int_cst_wide (type,
                              (precision - HOST_BITS_PER_WIDE_INT > 0
                               ? 0
-                              : (HOST_WIDE_INT) (-1) << (precision - 1)),
+                              : HOST_WIDE_INT_M1U << (precision - 1)),
                              (((HOST_WIDE_INT) (-1)
                                << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
                                    ? precision - HOST_BITS_PER_WIDE_INT - 1