From: Jakub Jelinek Date: Tue, 16 Aug 2016 16:48:16 +0000 (+0200) Subject: re PR middle-end/67485 (expmed.c sanitizer detects overflow) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1b13411a13e274d5e01b73704df9edd2639eedb4;p=gcc.git re PR middle-end/67485 (expmed.c sanitizer detects overflow) PR middle-end/67485 * expmed.c (expand_mult_const): Change val_so_far's type to UHWI, only cast it to SHWI for the final comparison. * gcc.c-torture/compile/pr67485.c: New test. From-SVN: r239507 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index df133208b2c..e2bec5f87ae 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-08-16 Jakub Jelinek + + PR middle-end/67485 + * expmed.c (expand_mult_const): Change val_so_far's type to UHWI, + only cast it to SHWI for the final comparison. + 2016-08-16 Martin Liska PR gcov-profile/36412 diff --git a/gcc/expmed.c b/gcc/expmed.c index 674c8f08928..1cedf023c8e 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -3055,7 +3055,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, rtx target, const struct algorithm *alg, enum mult_variant variant) { - HOST_WIDE_INT val_so_far; + unsigned HOST_WIDE_INT val_so_far; rtx_insn *insn; rtx accum, tem; int opno; @@ -3105,14 +3105,14 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, tem = expand_shift (LSHIFT_EXPR, mode, op0, log, NULL_RTX, 0); accum = force_operand (gen_rtx_PLUS (mode, accum, tem), add_target ? add_target : accum_target); - val_so_far += HOST_WIDE_INT_1 << log; + val_so_far += HOST_WIDE_INT_1U << log; break; case alg_sub_t_m2: tem = expand_shift (LSHIFT_EXPR, mode, op0, log, NULL_RTX, 0); accum = force_operand (gen_rtx_MINUS (mode, accum, tem), add_target ? add_target : accum_target); - val_so_far -= HOST_WIDE_INT_1 << log; + val_so_far -= HOST_WIDE_INT_1U << log; break; case alg_add_t2_m: @@ -3188,7 +3188,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, nmode = GET_MODE_INNER (mode); val &= GET_MODE_MASK (nmode); val_so_far &= GET_MODE_MASK (nmode); - gcc_assert (val == val_so_far); + gcc_assert (val == (HOST_WIDE_INT) val_so_far); return accum; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f39434dfc8d..f9668c9229f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2016-08-16 Jakub Jelinek + PR middle-end/67485 + * gcc.c-torture/compile/pr67485.c: New test. + PR target/72867 * gcc.target/i386/pr72867.c: Add -msse to dg-options. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr67485.c b/gcc/testsuite/gcc.c-torture/compile/pr67485.c new file mode 100644 index 00000000000..05098f93fa2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr67485.c @@ -0,0 +1,7 @@ +/* PR middle-end/67485 */ + +long int +foo (long int x) +{ + return x * __LONG_MAX__; +}