PR63426 Fix various signed integer overflows

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.

From-SVN: r217886
This commit is contained in:
Markus Trippelsdorf 2014-11-20 16:36:14 +00:00 committed by Markus Trippelsdorf
parent 46ed60245a
commit d7ca26e416
8 changed files with 23 additions and 10 deletions

View 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

View File

@ -176,7 +176,7 @@
(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

View File

@ -408,7 +408,7 @@
(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")))

View 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);

View 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++)

View 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);

View 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,

View 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;