Fix two ubsan failures (PR85164)
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 18 Apr 2019 12:29:56 +0000 (12:29 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 18 Apr 2019 12:29:56 +0000 (12:29 +0000)
commitcd7f7c54a43c435152b2ac76b6e74ae6a3430472
treed7ec130591e850d27f196e742e40bfba9f1d7602
parente62817edaecb4c8cb5a4f3c608f0ea52276449a1
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
gcc/ChangeLog
gcc/combine.c
gcc/rtlanal.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr85164-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr85164-2.c [new file with mode: 0644]