diff options
author | trippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-20 16:36:14 +0000 |
---|---|---|
committer | trippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-20 16:36:14 +0000 |
commit | 06b8401d563d626786964701f16ced1008d39593 (patch) | |
tree | bd5b144b7bbe1e7b714275f855291e53127e214a | |
parent | 650ad49efde0cfb457804acae1acd8d86f921fd4 (diff) | |
download | gcc-06b8401d563d626786964701f16ced1008d39593.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217886 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/config/rs6000/constraints.md | 2 | ||||
-rw-r--r-- | gcc/config/rs6000/predicates.md | 2 | ||||
-rw-r--r-- | gcc/config/rs6000/rs6000.c | 6 | ||||
-rw-r--r-- | gcc/emit-rtl.c | 2 | ||||
-rw-r--r-- | gcc/loop-iv.c | 4 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ivopts.c | 2 | ||||
-rw-r--r-- | gcc/varasm.c | 2 |
8 files changed, 23 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3cbdb6f5376..5f25791af2d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md index 0e0e517d7a1..3f12b07e489 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 1767cbd7a11..ea230a5b29a 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 506daa1d31e..a9604cf3fa9 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 1226aad0c13..fa5e41beb46 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -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++) diff --git a/gcc/loop-iv.c b/gcc/loop-iv.c index 8ea458c3fc5..f55cea2a985 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 4007e5483b2..fca18b6cdfe 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 07eb72aee31..99dae5d7098 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -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; |