re PR c/53968 (integer undefined behaviors in GCC)
authorJakub Jelinek <jakub@redhat.com>
Mon, 13 Aug 2012 12:39:54 +0000 (14:39 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 13 Aug 2012 12:39:54 +0000 (14:39 +0200)
PR c/53968
* tree.c (integer_pow2p): Avoid undefined signed overflows.
* simplify-rtx.c (neg_const_int): Likewise.
* expr.c (fixup_args_size_notes): Likewise.
* stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
* double-int.c (mul_double_wide_with_sign): Likewise.
(double_int_mask): Likewise.
* tree-ssa-loop-ivopts.c (get_address_cost): Likewise.

From-SVN: r190342

gcc/ChangeLog
gcc/double-int.c
gcc/expr.c
gcc/simplify-rtx.c
gcc/stor-layout.c
gcc/tree-ssa-loop-ivopts.c
gcc/tree.c

index acdfadb50eba73a909ddf07ab74c9211b38fd829..9c7fffe1053093069cc6212326b6776e22b003ca 100644 (file)
@@ -1,3 +1,14 @@
+2012-08-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/53968
+       * tree.c (integer_pow2p): Avoid undefined signed overflows.
+       * simplify-rtx.c (neg_const_int): Likewise.
+       * expr.c (fixup_args_size_notes): Likewise.
+       * stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
+       * double-int.c (mul_double_wide_with_sign): Likewise.
+       (double_int_mask): Likewise.
+       * tree-ssa-loop-ivopts.c (get_address_cost): Likewise.
+
 2012-08-13  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/54200
index 1204dc77aadf226699f8e6301e581abaadc6a1b6..ea518e3b41101307de0fcb53626d7c31836f713f 100644 (file)
@@ -170,7 +170,7 @@ mul_double_wide_with_sign (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
        {
          k = i + j;
          /* This product is <= 0xFFFE0001, the sum <= 0xFFFF0000.  */
-         carry += arg1[i] * arg2[j];
+         carry += (unsigned HOST_WIDE_INT) arg1[i] * arg2[j];
          /* Since prod[p] < 0xFFFF, this sum <= 0xFFFFFFFF.  */
          carry += prod[k];
          prod[k] = LOWPART (carry);
@@ -625,7 +625,7 @@ double_int_mask (unsigned prec)
   else
     {
       mask.high = 0;
-      mask.low = ((unsigned HOST_WIDE_INT) 2 << (prec - 1)) - 1;
+      mask.low = prec ? ((unsigned HOST_WIDE_INT) 2 << (prec - 1)) - 1 : 0;
     }
 
   return mask;
index 69e043dd4d9967e1a6ca979237f70bb87d1d1200..4e7eb5fbf4ce1c0444bcef7807893334fc0ea436 100644 (file)
@@ -3828,7 +3828,7 @@ fixup_args_size_notes (rtx prev, rtx last, int end_args_size)
 
       add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
 #ifdef STACK_GROWS_DOWNWARD
-      this_delta = -this_delta;
+      this_delta = -(unsigned HOST_WIDE_INT) this_delta;
 #endif
       args_size -= this_delta;
     }
index f56a5edef8f5f8d0322e39bf60a80f1739ca4b5e..16dbd8a03eaf3f0503e52f6a003f10736db288a5 100644 (file)
@@ -66,7 +66,7 @@ static rtx simplify_binary_operation_1 (enum rtx_code, enum machine_mode,
 static rtx
 neg_const_int (enum machine_mode mode, const_rtx i)
 {
-  return gen_int_mode (- INTVAL (i), mode);
+  return gen_int_mode (-(unsigned HOST_WIDE_INT) INTVAL (i), mode);
 }
 
 /* Test whether expression, X, is an immediate constant that represents
index ddec141a0c9104fff1daf8fa1074b03104f268a9..53554a9f45ea848e99bf0996688792624f5eb40d 100644 (file)
@@ -1,7 +1,7 @@
 /* C-compiler utilities for types and variables storage layout
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1996, 1998,
    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-   2011 Free Software Foundation, Inc.
+   2011, 2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -2568,10 +2568,14 @@ set_min_and_max_values_for_integral_type (tree type,
        = build_int_cst_wide (type,
                              (precision - HOST_BITS_PER_WIDE_INT > 0
                               ? -1
-                              : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
+                              : (HOST_WIDE_INT)
+                                (((unsigned HOST_WIDE_INT) 1
+                                  << (precision - 1)) - 1)),
                              (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
-                              ? (((HOST_WIDE_INT) 1
-                                  << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
+                              ? (HOST_WIDE_INT)
+                                ((((unsigned HOST_WIDE_INT) 1
+                                   << (precision - HOST_BITS_PER_WIDE_INT
+                                       - 1))) - 1)
                               : 0));
     }
 
index c44567fd27541c20c9e0d83353c731b20fa6a6ca..81271a705bae6aea5995c7539eb7f387be5d6fa9 100644 (file)
@@ -1,5 +1,5 @@
 /* Induction variable optimizations.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -3173,7 +3173,7 @@ get_address_cost (bool symbol_present, bool var_present,
 
       for (i = width; i >= 0; i--)
        {
-         off = -((HOST_WIDE_INT) 1 << i);
+         off = -((unsigned HOST_WIDE_INT) 1 << i);
          XEXP (addr, 1) = gen_int_mode (off, address_mode);
          if (memory_address_addr_space_p (mem_mode, addr, as))
            break;
@@ -3182,7 +3182,7 @@ get_address_cost (bool symbol_present, bool var_present,
 
       for (i = width; i >= 0; i--)
        {
-         off = ((HOST_WIDE_INT) 1 << i) - 1;
+         off = ((unsigned HOST_WIDE_INT) 1 << i) - 1;
          XEXP (addr, 1) = gen_int_mode (off, address_mode);
          if (memory_address_addr_space_p (mem_mode, addr, as))
            break;
index 6e864c38a23ff98a4a5eeea602d3f0ef28bd60bb..279850a1a84a8c7e31881b83e8bafb1db13610a5 100644 (file)
@@ -1849,7 +1849,7 @@ int
 integer_pow2p (const_tree expr)
 {
   int prec;
-  HOST_WIDE_INT high, low;
+  unsigned HOST_WIDE_INT high, low;
 
   STRIP_NOPS (expr);