This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR80362
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 Apr 2017 11:00:16 +0200 (CEST)
- Subject: [PATCH] Fix PR80362
- Authentication-results: sourceware.org; auth=none
I am testing the following.
Bootstrap / regtest running on x86_64-unknown-linux-gnu.
Richard.
2017-04-10 Richard Biener <rguenther@suse.de>
PR middle-end/80362
* fold-const.c (fold_binary_loc): Look at unstripped ops when
looking for NEGATE_EXPR in -A / -B to A / B folding.
* gcc.dg/torture/pr80362.c: New testcase.
Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c (revision 246797)
--- gcc/fold-const.c (working copy)
*************** fold_binary_loc (location_t loc,
*** 10205,10211 ****
/* Convert -A / -B to A / B when the type is signed and overflow is
undefined. */
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
! && TREE_CODE (arg0) == NEGATE_EXPR
&& negate_expr_p (op1))
{
if (INTEGRAL_TYPE_P (type))
--- 10205,10211 ----
/* Convert -A / -B to A / B when the type is signed and overflow is
undefined. */
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
! && TREE_CODE (op0) == NEGATE_EXPR
&& negate_expr_p (op1))
{
if (INTEGRAL_TYPE_P (type))
Index: gcc/testsuite/gcc.dg/torture/pr80362.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr80362.c (nonexistent)
--- gcc/testsuite/gcc.dg/torture/pr80362.c (working copy)
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do run } */
+ /* { dg-additional-options "-fstrict-overflow" } */
+
+ int main()
+ {
+ signed char var_0, var_1 = -128;
+ var_0 = (signed char)(-var_1) / 3;
+ if (var_0 > 0)
+ __builtin_abort();
+ }