OSDN Git Service

./:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 27 Sep 2007 17:31:34 +0000 (17:31 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 27 Sep 2007 17:31:34 +0000 (17:31 +0000)
PR tree-optimization/33565
* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING on
assignments of comparisons.
* tree-ssa-sccvn.c (simplify_binary_expression): Add stmt
parameter.  Change caller.  Defer overflow warnings around call to
fold_binary.
* fold-const.c (fold_undefer_overflow_warnings): Don't warn if
TREE_NO_WARNING is set on the statement.
* tree-ssa-forwprop.c
(tree_ssa_forward_propagate_single_use_vars): Don't test
TREE_NO_WARNING when calling fold_undefer_overflow_warnings.
* tree-cfg.c (fold_cond_expr_cond): Likewise.
testsuite/:
PR tree-optimization/33565
* gcc.dg/Wstrict-overflow-20.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128840 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstrict-overflow-20.c [new file with mode: 0644]
gcc/tree-cfg.c
gcc/tree-ssa-forwprop.c
gcc/tree-ssa-loop-ch.c
gcc/tree-ssa-sccvn.c

index f7a4382..78ef879 100644 (file)
@@ -1,3 +1,18 @@
+2007-09-27  Ian Lance Taylor  <iant@google.com>
+
+       PR tree-optimization/33565
+       * tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING on
+       assignments of comparisons.
+       * tree-ssa-sccvn.c (simplify_binary_expression): Add stmt
+       parameter.  Change caller.  Defer overflow warnings around call to
+       fold_binary.
+       * fold-const.c (fold_undefer_overflow_warnings): Don't warn if
+       TREE_NO_WARNING is set on the statement.
+       * tree-ssa-forwprop.c
+       (tree_ssa_forward_propagate_single_use_vars): Don't test
+       TREE_NO_WARNING when calling fold_undefer_overflow_warnings.
+       * tree-cfg.c (fold_cond_expr_cond): Likewise.
+
 2007-09-27  Joseph Myers  <joseph@codesourcery.com>
 
        * config/rs6000/rs6000.c (rs6000_legitimize_address): Do not
index 12413d8..62cbfd1 100644 (file)
@@ -974,6 +974,9 @@ fold_undefer_overflow_warnings (bool issue, const_tree stmt, int code)
   if (!issue || warnmsg == NULL)
     return;
 
+  if (stmt != NULL_TREE && TREE_NO_WARNING (stmt))
+    return;
+
   /* Use the smallest code level when deciding to issue the
      warning.  */
   if (code == 0 || code > (int) fold_deferred_overflow_code)
index e7b5252..163f80b 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-27  Ian Lance Taylor  <iant@google.com>
+
+       PR tree-optimization/33565
+       * gcc.dg/Wstrict-overflow-20.c: New test.
+
 2007-09-27  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * gfortran.dg/openmp_stack.f90: Fix typo.
diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-20.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-20.c
new file mode 100644 (file)
index 0000000..207162d
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow" } */
+
+/* Don't warn about an overflow in a copied loop header.  We used to
+   get a warning in value numbering.  This is PR 33565.  */
+
+void f (int m, int n)
+{
+  int j;
+  for (j = m; j        < m + 10 && j < n; j ++)
+    do_something (j);
+}
index fd981f3..320bc8e 100644 (file)
@@ -417,8 +417,7 @@ fold_cond_expr_cond (void)
          cond = fold (COND_EXPR_COND (stmt));
          zerop = integer_zerop (cond);
          onep = integer_onep (cond);
-         fold_undefer_overflow_warnings (((zerop || onep)
-                                          && !TREE_NO_WARNING (stmt)),
+         fold_undefer_overflow_warnings (zerop || onep,
                                          stmt,
                                          WARN_STRICT_OVERFLOW_CONDITIONAL);
          if (zerop)
index e026b80..60e6ffa 100644 (file)
@@ -1021,8 +1021,7 @@ tree_ssa_forward_propagate_single_use_vars (void)
              did_something = forward_propagate_into_cond (stmt, stmt);
              if (did_something == 2)
                cfg_changed = true;
-             fold_undefer_overflow_warnings (!TREE_NO_WARNING (stmt)
-                                             && did_something, stmt,
+             fold_undefer_overflow_warnings (did_something, stmt,
                                              WARN_STRICT_OVERFLOW_CONDITIONAL);
              bsi_next (&bsi);
            }
index e895981..ff62c68 100644 (file)
@@ -215,11 +215,22 @@ copy_loop_headers (void)
 
          for (i = 0; i < n_bbs; ++i)
            {
-             tree last;
-
-             last = last_stmt (copied_bbs[i]);
-             if (TREE_CODE (last) == COND_EXPR)
-               TREE_NO_WARNING (last) = 1;
+             block_stmt_iterator bsi;
+
+             for (bsi = bsi_start (copied_bbs[i]);
+                  !bsi_end_p (bsi);
+                  bsi_next (&bsi))
+               {
+                 tree stmt = bsi_stmt (bsi);
+                 if (TREE_CODE (stmt) == COND_EXPR)
+                   TREE_NO_WARNING (stmt) = 1;
+                 else if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
+                   {
+                     tree rhs = GIMPLE_STMT_OPERAND (stmt, 1);
+                     if (COMPARISON_CLASS_P (rhs))
+                       TREE_NO_WARNING (stmt) = 1;
+                   }
+               }
            }
        }
 
index cddd2d1..b4fb014 100644 (file)
@@ -1390,7 +1390,7 @@ valueize_expr (tree expr)
    simplified. */
 
 static tree
-simplify_binary_expression (tree rhs)
+simplify_binary_expression (tree stmt, tree rhs)
 {
   tree result = NULL_TREE;
   tree op0 = TREE_OPERAND (rhs, 0);
@@ -1421,8 +1421,13 @@ simplify_binary_expression (tree rhs)
       && op1 == TREE_OPERAND (rhs, 1))
     return NULL_TREE;
 
+  fold_defer_overflow_warnings ();
+
   result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1);
 
+  fold_undefer_overflow_warnings (result && valid_gimple_expression_p (result),
+                                 stmt, 0);
+
   /* Make sure result is not a complex expression consisting
      of operators of operators (IE (a + b) + (a + c))
      Otherwise, we will end up with unbounded expressions if
@@ -1522,7 +1527,7 @@ try_to_simplify (tree stmt, tree rhs)
          break;
        case tcc_comparison:
        case tcc_binary:
-         return simplify_binary_expression (rhs);
+         return simplify_binary_expression (stmt, rhs);
          break;
        default:
          break;