[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Marek Polacek  ---
Fixed for GCC 8.

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

--- Comment #8 from Marek Polacek  ---
Author: mpolacek
Date: Wed Jul 26 11:53:17 2017
New Revision: 250566

URL: https://gcc.gnu.org/viewcvs?rev=250566=gcc=rev
Log:
PR middle-end/70992
* tree.c (build2_stat): Don't set TREE_CONSTANT on divisions by zero.

* gcc.dg/overflow-warn-1.c: Adjust dg-error.
* gcc.dg/overflow-warn-2.c: Likewise.
* gcc.dg/overflow-warn-3.c: Likewise.
* gcc.dg/overflow-warn-4.c: Likewise.
* gcc.dg/torture/pr70992-2.c: New test.
* gcc.dg/torture/pr70992.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/torture/pr70992-2.c
trunk/gcc/testsuite/gcc.dg/torture/pr70992.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/overflow-warn-1.c
trunk/gcc/testsuite/gcc.dg/overflow-warn-2.c
trunk/gcc/testsuite/gcc.dg/overflow-warn-3.c
trunk/gcc/testsuite/gcc.dg/overflow-warn-4.c
trunk/gcc/tree.c

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

--- Comment #7 from Marek Polacek  ---
We can simply do:
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9387,6 +9387,11 @@ fold_binary_loc (location_t loc,
  TREE_TYPE (arg0), arg0,
  cst0));
}
+ /* Adding anything to a division-by-zero makes no sense and
+can confuse extract_muldiv and fold_plusminus_mult_expr.  */
+ else if (TREE_CODE (arg0) == TRUNC_DIV_EXPR
+  && integer_zerop (TREE_OPERAND (arg0, 1)))
+   return fold_convert_loc (loc, type, arg0);
}

   /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the same or

(In reply to Alexander Monakov from comment #6)
> We can simply fold A / 0 * B and A / 0 + B to 1 / 0 or 0 / 0.
> 
> I wonder why fold_plusminus_mult_expr puts the addition inside, that doesn't
> appear useful?

fold_plusminus_mult_expr tries to turn e.g. 2*a + a into 3*a, so that's where
the + 1 comes from.

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-17 Thread amonakov at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Alexander Monakov  changed:

   What|Removed |Added

 CC||amonakov at gcc dot gnu.org

--- Comment #6 from Alexander Monakov  ---
We can simply fold A / 0 * B and A / 0 + B to 1 / 0 or 0 / 0.

I wonder why fold_plusminus_mult_expr puts the addition inside, that doesn't
appear useful?

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-17 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #5 from Marek Polacek  ---
I can confirm that even Comment 4 is the same extract_muldiv_1 <->
fold_plusminus_mult_expr issue:

((2147483648 / 0) * 2) + 2
<->
2 * (2147483648 / 0 + 1)

So the question is: where should we break the tie?

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2017-07-11 Thread asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Arseny Solokha  changed:

   What|Removed |Added

  Known to fail||8.0

--- Comment #4 from Arseny Solokha  ---
The following makes gcc-8.0.0-alpha20170709 snapshot ICE w/ no command line
options at all:

typedef unsigned int uint32_t;

uint32_t
ls (uint32_t so)
{
  return (so + so) * (0x8000 / 0 + 1);
}

% gcc-8.0.0-alpha20170709 -c -w sxijy9dr.c
x86_64-unknown-linux-gnu-gcc-8.0.0-alpha20170709: internal compiler error:
Segmentation fault (program cc1)

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2016-05-30 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

--- Comment #3 from Richard Biener  ---
The bad recursion happens between extract_muldiv_1

  /* The last case is if we are a multiply.  In that case, we can
 apply the distributive law to commute the multiply and addition
 if the multiplication of the constants doesn't overflow
 and overflow is defined.  With undefined overflow
 op0 * c might overflow, while (op0 + orig_op1) * c doesn't.  */
  if (code == MULT_EXPR && TYPE_OVERFLOW_WRAPS (ctype))
return fold_build2 (tcode, ctype,
fold_build2 (code, ctype,
 fold_convert (ctype, op0),
 fold_convert (ctype, c)),
op1);

which does (0 % 0 + 1) * 2 -> (0 % 0) * 2 + 2 and the reverse transformation
fold_plusminus_mult_expr does.

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2016-05-09 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

--- Comment #2 from Richard Biener  ---
I think the issue is that the associate case treats (0 % 0 + 1) * 2 as constant
but that gets further "simplified" when combined with the rest.

In the end our refusal to simplify 0 % 0 to 0 causes things to go downhill
(we _do_ simplify 0 % a to 0!)

 (for mod (ceil_mod floor_mod round_mod trunc_mod)
 /* 0 % X is always zero.  */
 (simplify
  (mod integer_zerop@0 @1)
  /* But not for 0 % 0 so that we can get the proper warnings and errors.  */
  (if (!integer_zerop (@1))
   @0))

[Bug middle-end/70992] Infinite recursion between fold_build2_stat_loc and fold_binary_loc w/ -fwrapv

2016-05-09 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70992

Richard Biener  changed:

   What|Removed |Added

   Keywords|ice-on-invalid-code |ice-on-valid-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-05-09
Version|unknown |6.1.0
 Ever confirmed|0   |1
  Known to fail||4.3.5

--- Comment #1 from Richard Biener  ---
Confirmed back to GCC 4.3.