Blob Blame History Raw
2017-09-18  Richard Biener  <rguenther@suse.de>

	Backport from mainline
	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.

--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -11940,8 +11942,8 @@ fold_binary_loc (location_t loc,
       /* 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 (arg1))
+	  && TREE_CODE (op0) == NEGATE_EXPR
+	  && negate_expr_p (op1))
 	{
 	  if (INTEGRAL_TYPE_P (type))
 	    fold_overflow_warning (("assuming signed overflow does not occur "
--- /dev/null
+++ gcc/testsuite/gcc.dg/torture/pr80362.c
@@ -0,0 +1,11 @@
+/* { 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();
+  return 0;
+}