From e0e5e0b3c95ee6d12424deaa2ceba6eb5d2be9f3 Mon Sep 17 00:00:00 2001 From: jakub Date: Mon, 13 Aug 2012 12:39:54 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@190342 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 11 +++++++++++ gcc/double-int.c | 4 ++-- gcc/expr.c | 2 +- gcc/simplify-rtx.c | 2 +- gcc/stor-layout.c | 12 ++++++++---- gcc/tree-ssa-loop-ivopts.c | 6 +++--- gcc/tree.c | 2 +- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index acdfadb50eb..9c7fffe1053 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2012-08-13 Jakub Jelinek + + 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 PR tree-optimization/54200 diff --git a/gcc/double-int.c b/gcc/double-int.c index 1204dc77aad..ea518e3b411 100644 --- a/gcc/double-int.c +++ b/gcc/double-int.c @@ -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; diff --git a/gcc/expr.c b/gcc/expr.c index 69e043dd4d9..4e7eb5fbf4c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -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; } diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index f56a5edef8f..16dbd8a03ea 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -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 diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index ddec141a0c9..53554a9f45e 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -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)); } diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index c44567fd275..81271a705ba 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -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; diff --git a/gcc/tree.c b/gcc/tree.c index 6e864c38a23..279850a1a84 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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); -- 2.11.4.GIT