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. Tested on powerpc64-unknown-linux-gnu. OK for trunk? Thanks. 2014-11-20 Markus Trippelsdorf <mar...@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. diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md index 0e0e517d7a1d..3f12b07e4899 100644 --- a/gcc/config/rs6000/constraints.md +++ b/gcc/config/rs6000/constraints.md @@ -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 diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index 1767cbd7a11b..ea230a5b29a6 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -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"))) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 506daa1d31e7..a9604cf3fa97 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -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); diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c index 04f677eb608d..9d60d42c01f8 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -203,7 +203,7 @@ static hashval_t const_wide_int_htab_hash (const void *x) { int i; - HOST_WIDE_INT hash = 0; + unsigned HOST_WIDE_INT hash = 0; const_rtx xr = (const_rtx) x; for (i = 0; i < CONST_WIDE_INT_NUNITS (xr); i++) diff --git a/gcc/loop-iv.c b/gcc/loop-iv.c index 8ea458c3fc53..f55cea2a9859 100644 --- a/gcc/loop-iv.c +++ b/gcc/loop-iv.c @@ -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); diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 4007e5483b27..fca18b6cdfe3 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -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, diff --git a/gcc/varasm.c b/gcc/varasm.c index 54611f8fd3f1..b93e2559843c 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -7188,7 +7188,7 @@ get_section_anchor (struct object_block *block, HOST_WIDE_INT offset, offset = 0; else { - bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1); + bias = (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (ptr_mode) - 1); if (offset < 0) { delta = -(unsigned HOST_WIDE_INT) offset + max_offset; -- Markus