Commit eb87c7c4 by Jakub Jelinek Committed by Jakub Jelinek

re PR c/53968 (integer undefined behaviors in GCC)

	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
parent 6a9573cc
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
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
/* 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));
}
......
/* 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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment