Commit 1b13411a by Jakub Jelinek Committed by Jakub Jelinek

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
parent 4a7f57d5
2016-08-16 Jakub Jelinek <jakub@redhat.com>
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 <mliska@suse.cz> 2016-08-16 Martin Liska <mliska@suse.cz>
PR gcov-profile/36412 PR gcov-profile/36412
......
...@@ -3055,7 +3055,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, ...@@ -3055,7 +3055,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val,
rtx target, const struct algorithm *alg, rtx target, const struct algorithm *alg,
enum mult_variant variant) enum mult_variant variant)
{ {
HOST_WIDE_INT val_so_far; unsigned HOST_WIDE_INT val_so_far;
rtx_insn *insn; rtx_insn *insn;
rtx accum, tem; rtx accum, tem;
int opno; int opno;
...@@ -3105,14 +3105,14 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, ...@@ -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); tem = expand_shift (LSHIFT_EXPR, mode, op0, log, NULL_RTX, 0);
accum = force_operand (gen_rtx_PLUS (mode, accum, tem), accum = force_operand (gen_rtx_PLUS (mode, accum, tem),
add_target ? add_target : accum_target); add_target ? add_target : accum_target);
val_so_far += HOST_WIDE_INT_1 << log; val_so_far += HOST_WIDE_INT_1U << log;
break; break;
case alg_sub_t_m2: case alg_sub_t_m2:
tem = expand_shift (LSHIFT_EXPR, mode, op0, log, NULL_RTX, 0); tem = expand_shift (LSHIFT_EXPR, mode, op0, log, NULL_RTX, 0);
accum = force_operand (gen_rtx_MINUS (mode, accum, tem), accum = force_operand (gen_rtx_MINUS (mode, accum, tem),
add_target ? add_target : accum_target); add_target ? add_target : accum_target);
val_so_far -= HOST_WIDE_INT_1 << log; val_so_far -= HOST_WIDE_INT_1U << log;
break; break;
case alg_add_t2_m: case alg_add_t2_m:
...@@ -3188,7 +3188,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val, ...@@ -3188,7 +3188,7 @@ expand_mult_const (machine_mode mode, rtx op0, HOST_WIDE_INT val,
nmode = GET_MODE_INNER (mode); nmode = GET_MODE_INNER (mode);
val &= GET_MODE_MASK (nmode); val &= GET_MODE_MASK (nmode);
val_so_far &= 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; return accum;
} }
......
2016-08-16 Jakub Jelinek <jakub@redhat.com> 2016-08-16 Jakub Jelinek <jakub@redhat.com>
PR middle-end/67485
* gcc.c-torture/compile/pr67485.c: New test.
PR target/72867 PR target/72867
* gcc.target/i386/pr72867.c: Add -msse to dg-options. * gcc.target/i386/pr72867.c: Add -msse to dg-options.
......
/* PR middle-end/67485 */
long int
foo (long int x)
{
return x * __LONG_MAX__;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment