]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorRichard Biener <rguenther@suse.de>
Thu, 21 Jun 2018 09:50:36 +0000 (09:50 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 21 Jun 2018 09:50:36 +0000 (09:50 +0000)
2018-06-21  Richard Biener  <rguenther@suse.de>

Backport from mainline
2018-02-28  Richard Biener  <rguenther@suse.de>

PR middle-end/84607
* genmatch.c (capture_info::walk_match): Do not mark
captured expressions without operands as expr_p given
they act more like predicates and should be subject to
"lost tail" side-effect preserving.

* gcc.dg/pr84607.c: New testcase.

2018-05-04  Richard Biener  <rguenther@suse.de>

PR middle-end/85588
* fold-const.c (negate_expr_p): Restrict negation of operand
zero of a division to when we know that can happen without
overflow.
(fold_negate_expr_1): Likewise.

* gcc.dg/torture/pr85588.c: New testcase.
* gcc.dg/torture/pr57656.c: Use dg-additional-options.

From-SVN: r261839

gcc/ChangeLog
gcc/fold-const.c
gcc/genmatch.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84607.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr57656.c
gcc/testsuite/gcc.dg/torture/pr85588.c [new file with mode: 0644]

index 0ad4c907ac7afb155f21aae9c3af71b3057c534d..3ac7879f610b655656d56600bc2dcb4b4421e841 100644 (file)
@@ -1,3 +1,22 @@
+2018-06-21  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2018-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/84607
+       * genmatch.c (capture_info::walk_match): Do not mark
+       captured expressions without operands as expr_p given
+       they act more like predicates and should be subject to
+       "lost tail" side-effect preserving.
+
+       2018-05-04  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/85588
+       * fold-const.c (negate_expr_p): Restrict negation of operand
+       zero of a division to when we know that can happen without
+       overflow.
+       (fold_negate_expr_1): Likewise.
+
 2018-06-21  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
index 508c02d7746b7796a71ae9f230c5bd044da21619..0d575d0548ce8438de263cb46b88daebf2bc10c5 100644 (file)
@@ -481,12 +481,15 @@ negate_expr_p (tree t)
     case EXACT_DIV_EXPR:
       if (TYPE_UNSIGNED (type))
        break;
-      if (negate_expr_p (TREE_OPERAND (t, 0)))
+      /* In general we can't negate A in A / B, because if A is INT_MIN and
+         B is not 1 we change the sign of the result.  */
+      if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
+         && negate_expr_p (TREE_OPERAND (t, 0)))
        return true;
       /* In general we can't negate B in A / B, because if A is INT_MIN and
         B is 1, we may turn this into INT_MIN / -1 which is undefined
         and actually traps on some architectures.  */
-      if (! INTEGRAL_TYPE_P (TREE_TYPE (t))
+      if (! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
          || TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
          || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
              && ! integer_onep (TREE_OPERAND (t, 1))))
@@ -663,14 +666,17 @@ fold_negate_expr_1 (location_t loc, tree t)
     case EXACT_DIV_EXPR:
       if (TYPE_UNSIGNED (type))
        break;
-      if (negate_expr_p (TREE_OPERAND (t, 0)))
+      /* In general we can't negate A in A / B, because if A is INT_MIN and
+        B is not 1 we change the sign of the result.  */
+      if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
+         && negate_expr_p (TREE_OPERAND (t, 0)))
        return fold_build2_loc (loc, TREE_CODE (t), type,
                                negate_expr (TREE_OPERAND (t, 0)),
                                TREE_OPERAND (t, 1));
       /* In general we can't negate B in A / B, because if A is INT_MIN and
         B is 1, we may turn this into INT_MIN / -1 which is undefined
         and actually traps on some architectures.  */
-      if ((! INTEGRAL_TYPE_P (TREE_TYPE (t))
+      if ((! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
           || TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
           || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
               && ! integer_onep (TREE_OPERAND (t, 1))))
index 40b7674239d0e43bcec4065d92f7f1858f61e491..719adbb3c9650ca85384b4be65967d04da7d85db 100644 (file)
@@ -1930,7 +1930,11 @@ capture_info::walk_match (operand *o, unsigned toplevel_arg,
       if (c->what
          && (e = dyn_cast <expr *> (c->what)))
        {
-         info[where].expr_p = true;
+         /* Zero-operand expression captures like ADDR_EXPR@0 are
+            similar as predicates -- if they are not mentioned in
+            the result we have to force them to have no side-effects.  */
+         if (e->ops.length () != 0)
+           info[where].expr_p = true;
          info[where].force_single_use |= e->force_single_use;
        }
     }
index bc02092f8bfc8935356e5f4096f15b5646278fc6..071b121c73c4396a6fdb485648f9dbf7a9775c7d 100644 (file)
@@ -1,3 +1,17 @@
+2018-06-21  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2018-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/84607
+       * gcc.dg/pr84607.c: New testcase.
+
+       2018-05-04  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/85588
+       * gcc.dg/torture/pr85588.c: New testcase.
+       * gcc.dg/torture/pr57656.c: Use dg-additional-options.
+
 2018-06-21  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/pr84607.c b/gcc/testsuite/gcc.dg/pr84607.c
new file mode 100644 (file)
index 0000000..710ee94
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+extern void exit(int);
+extern void abort(void);
+int a[10];
+int foo()
+{
+  exit (0);
+  return 0;
+}
+int main()
+{
+  if (&a[foo()])
+    abort ();
+  return 0;
+}
index 4f3645e4693ea2895bdb1e50eb42448f8d579cc4..02490140105984cc4cf424912fbebbd2e77ddcb5 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-fstrict-overflow" } */
+/* { dg-additional-options "-fstrict-overflow" } */
 
 int main (void)
 {
diff --git a/gcc/testsuite/gcc.dg/torture/pr85588.c b/gcc/testsuite/gcc.dg/torture/pr85588.c
new file mode 100644 (file)
index 0000000..5d95c96
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fwrapv" } */
+
+#include "pr57656.c"