aboutsummaryrefslogtreecommitdiff
path: root/gcc/combine.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-04-18 12:29:56 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-04-18 12:29:56 +0000
commitcd7f7c54a43c435152b2ac76b6e74ae6a3430472 (patch)
treed7ec130591e850d27f196e742e40bfba9f1d7602 /gcc/combine.c
parente62817edaecb4c8cb5a4f3c608f0ea52276449a1 (diff)
downloadgcc-cd7f7c54a43c435152b2ac76b6e74ae6a3430472.zip
gcc-cd7f7c54a43c435152b2ac76b6e74ae6a3430472.tar.gz
gcc-cd7f7c54a43c435152b2ac76b6e74ae6a3430472.tar.bz2
Fix two ubsan failures (PR85164)
Two fixes for UB when handling very large offsets. The calculation in force_int_to_mode would have been correct if signed integers used modulo arithmetic, so just switch to unsigned types. The calculation in rtx_addr_can_trap_p_1 didn't handle overflow properly, so switch to known_subrange_p instead (which is supposed to handle all cases). 2019-04-18 Richard Sandiford <richard.sandiford@arm.com> gcc/ PR middle-end/85164 * combine.c (force_int_to_mode): Cast the argument rather than the result of known_alignment. * rtlanal.c (rtx_addr_can_trap_p_1): Use known_subrange_p. gcc/testsuite/ PR middle-end/85164 * gcc.dg/pr85164-1.c, gcc.dg/pr85164-2.c: New tests. From-SVN: r270442
Diffstat (limited to 'gcc/combine.c')
-rw-r--r--gcc/combine.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/combine.c b/gcc/combine.c
index 5616e6b..4de759a 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -8946,7 +8946,7 @@ force_int_to_mode (rtx x, scalar_int_mode mode, scalar_int_mode xmode,
/* If X is (minus C Y) where C's least set bit is larger than any bit
in the mask, then we may replace with (neg Y). */
if (poly_int_rtx_p (XEXP (x, 0), &const_op0)
- && (unsigned HOST_WIDE_INT) known_alignment (const_op0) > mask)
+ && known_alignment (poly_uint64 (const_op0)) > mask)
{
x = simplify_gen_unary (NEG, xmode, XEXP (x, 1), xmode);
return force_to_mode (x, mode, mask, next_select);