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
This commit is contained in:
Jakub Jelinek 2016-08-16 18:48:16 +02:00 committed by Jakub Jelinek
parent 4a7f57d539
commit 1b13411a13
4 changed files with 20 additions and 4 deletions

View File

@ -1,3 +1,9 @@
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>
PR gcov-profile/36412

View File

@ -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;
}

View File

@ -1,5 +1,8 @@
2016-08-16 Jakub Jelinek <jakub@redhat.com>
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.

View File

@ -0,0 +1,7 @@
/* PR middle-end/67485 */
long int
foo (long int x)
{
return x * __LONG_MAX__;
}