Before handling the fold_overflow_warn() call from
tree_expr_nonnegative_warnv_p we'll remove all remaining
strict_overflow_p flags from the helpers that are still using it.

An ATTRIBUTE_UNUSED tag was added in the strict_overflow_p argument in
tree_expr_nonnegative_warnv_p because the variable is now unused, but
removing it right now will incur a lot of non-trivial changes that would
be too much for this patch. This tag, and all the extra lines we're
adding to make RECURSE() happy, will be dealt with in the next patch.

gimple-fold.cc functions got impacted by the changes and were changed
accordingly.

gcc/ChangeLog:

        * fold-const.cc (tree_call_nonnegative_warnv_p): Renamed to
        tree_call_nonnegative_warnv_p.
        (tree_call_nonnegative_p): Removed strict_overflow_p flag.
        (tree_invalid_nonnegative_warnv_p): Renamed to
        tree_invalid_nonnegative_p.
        (tree_invalid_nonnegative_p): Removed strict_overflow_p flag.
        (tree_expr_nonnegative_warnv_p): Added ATTRIBUTE_UNUSED tag in
        the now unused strict_overflow_p argument. Removed
        strict_overflow_p call from tree_invalid_nonnegative_p.
        * fold-const.h (tree_call_nonnegative_warnv_p): Renamed to
        tree_call_nonnegative_p.
        (tree_call_nonnegative_p): Removed strict_overflow_p flag.
        * gimple-fold.cc (gimple_call_nonnegative_warnv_p): Renamed to
        gimple_call_nonnegative_p.
        (gimple_call_nonnegative_p): Removed strict_overflow_p flag.
        (gimple_stmt_nonnegative_warnv_p): Renamed to
        gimple_stmt_nonnegative_p.
        (gimple_stmt_nonnegative_p): Removed strict_overflow_p flag.
        * gimple-fold.h (gimple_stmt_nonnegative_warnv_p): Renamed to
        gimple_stmt_nonnegative_p.
        (gimple_stmt_nonnegative_p): Removed strict_overflow_p flag.
        * gimple-range-fold.cc (fold_using_range::fold_stmt): Removed
        strict_overflow_p flag from gimple_stmt_nonnegative_p.
        (fold_using_range::range_of_call): Likewise.
---
 gcc/fold-const.cc        | 53 ++++++++++++++++++++++------------------
 gcc/fold-const.h         |  3 +--
 gcc/gimple-fold.cc       | 24 ++++++------------
 gcc/gimple-fold.h        |  2 +-
 gcc/gimple-range-fold.cc |  6 ++---
 5 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 550e1574425..3f08f2dee77 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -14819,23 +14819,25 @@ tree_single_nonnegative_p (tree t, int depth)
         to provide it through dataflow propagation.  */
       return (!name_registered_for_update_p (t)
              && depth < param_max_ssa_name_query_depth
-             && gimple_stmt_nonnegative_warnv_p (SSA_NAME_DEF_STMT (t),
-                                                 strict_overflow_p, depth));
+             && gimple_stmt_nonnegative_p (SSA_NAME_DEF_STMT (t), depth));
 
     default:
       return tree_simple_nonnegative_warnv_p (TREE_CODE (t), TREE_TYPE (t));
     }
 }
 
-/* Return true if T is known to be non-negative.  If the return
-   value is based on the assumption that signed overflow is undefined,
-   set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+/* Return true if T is known to be non-negative.
+   DEPTH is the current nesting depth of the query.  */
 
 bool
-tree_call_nonnegative_warnv_p (tree type, combined_fn fn, tree arg0, tree arg1,
-                              bool *strict_overflow_p, int depth)
+tree_call_nonnegative_p (tree type, combined_fn fn, tree arg0, tree arg1,
+                        int depth)
 {
+  /* The RECURSE () macro counts with a strict_overflow_p bool
+     pointer being declared beforehand.  */
+  bool val = false;
+  bool *strict_overflow_p = &val;
+
   switch (fn)
     {
     CASE_CFN_ACOS:
@@ -15013,18 +15015,21 @@ tree_call_nonnegative_warnv_p (tree type, combined_fn 
fn, tree arg0, tree arg1,
   return tree_simple_nonnegative_warnv_p (CALL_EXPR, type);
 }
 
-/* Return true if T is known to be non-negative.  If the return
-   value is based on the assumption that signed overflow is undefined,
-   set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+/* Return true if T is known to be non-negative.
+   DEPTH is the current nesting depth of the query.  */
 
 static bool
-tree_invalid_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
+tree_invalid_nonnegative_p (tree t, int depth)
 {
   enum tree_code code = TREE_CODE (t);
   if (TYPE_UNSIGNED (TREE_TYPE (t)))
     return true;
 
+  /* The RECURSE () macro counts with a strict_overflow_p bool
+     pointer being declared beforehand.  */
+  bool val = false;
+  bool *strict_overflow_p = &val;
+
   switch (code)
     {
     case TARGET_EXPR:
@@ -15063,11 +15068,11 @@ tree_invalid_nonnegative_warnv_p (tree t, bool 
*strict_overflow_p, int depth)
        tree arg0 = call_expr_nargs (t) > 0 ? CALL_EXPR_ARG (t, 0) : NULL_TREE;
        tree arg1 = call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE;
 
-       return tree_call_nonnegative_warnv_p (TREE_TYPE (t),
-                                             get_call_combined_fn (t),
-                                             arg0,
-                                             arg1,
-                                             strict_overflow_p, depth);
+       return tree_call_nonnegative_p (TREE_TYPE (t),
+                                       get_call_combined_fn (t),
+                                       arg0,
+                                       arg1,
+                                       depth);
       }
     case COMPOUND_EXPR:
     case MODIFY_EXPR:
@@ -15087,13 +15092,13 @@ tree_invalid_nonnegative_warnv_p (tree t, bool 
*strict_overflow_p, int depth)
 #undef RECURSE
 #undef tree_expr_nonnegative_warnv_p
 
-/* Return true if T is known to be non-negative.  If the return
-   value is based on the assumption that signed overflow is undefined,
-   set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+/* Return true if T is known to be non-negative.
+   DEPTH is the current nesting depth of the query.  */
 
 bool
-tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
+tree_expr_nonnegative_warnv_p (tree t,
+                              bool *strict_overflow_p ATTRIBUTE_UNUSED,
+                              int depth)
 {
   enum tree_code code;
   if (error_operand_p (t))
@@ -15150,7 +15155,7 @@ tree_expr_nonnegative_warnv_p (tree t, bool 
*strict_overflow_p, int depth)
       return tree_single_nonnegative_p (t, depth);
 
     default:
-      return tree_invalid_nonnegative_warnv_p (t, strict_overflow_p, depth);
+      return tree_invalid_nonnegative_p (t, depth);
     }
 }
 
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index bc2d619e3d7..30d044ae5fb 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -168,8 +168,7 @@ extern bool tree_single_nonzero_p (tree);
 extern bool tree_unary_nonnegative_p (enum tree_code, tree, tree, int);
 extern bool tree_binary_nonnegative_p (enum tree_code, tree, tree, tree, int);
 extern bool tree_single_nonnegative_p (tree, int);
-extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree,
-                                          bool *, int);
+extern bool tree_call_nonnegative_p (tree, combined_fn, tree, tree, int);
 
 extern bool integer_valued_real_unary_p (tree_code, tree, int);
 extern bool integer_valued_real_binary_p (tree_code, tree, tree, int);
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index e022099ab4c..c54629713a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -11421,13 +11421,10 @@ gimple_assign_nonnegative_p (gimple *stmt, int depth)
 }
 
 /* Return true if return value of call STMT is known to be non-negative.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+   DEPTH is the current nesting depth of the query.  */
 
 static bool
-gimple_call_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
-                                int depth)
+gimple_call_nonnegative_p (gimple *stmt, int depth)
 {
   tree arg0
     = gimple_call_num_args (stmt) > 0 ? gimple_call_arg (stmt, 0) : NULL_TREE;
@@ -11435,10 +11432,9 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool 
*strict_overflow_p,
     = gimple_call_num_args (stmt) > 1 ? gimple_call_arg (stmt, 1) : NULL_TREE;
   tree lhs = gimple_call_lhs (stmt);
   return (lhs
-         && tree_call_nonnegative_warnv_p (TREE_TYPE (lhs),
-                                           gimple_call_combined_fn (stmt),
-                                           arg0, arg1,
-                                           strict_overflow_p, depth));
+         && tree_call_nonnegative_p (TREE_TYPE (lhs),
+                                     gimple_call_combined_fn (stmt),
+                                     arg0, arg1, depth));
 }
 
 /* Return true if return value of call STMT is known to be non-negative.
@@ -11457,13 +11453,10 @@ gimple_phi_nonnegative_p (gimple *stmt, int depth)
 }
 
 /* Return true if STMT is known to compute a non-negative value.
-   If the return value is based on the assumption that signed overflow is
-   undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
-   *STRICT_OVERFLOW_P.  DEPTH is the current nesting depth of the query.  */
+   DEPTH is the current nesting depth of the query.  */
 
 bool
-gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
-                                int depth)
+gimple_stmt_nonnegative_p (gimple *stmt, int depth)
 {
   tree type = gimple_range_type (stmt);
   if (type && frange::supports_p (type))
@@ -11479,8 +11472,7 @@ gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool 
*strict_overflow_p,
     case GIMPLE_ASSIGN:
       return gimple_assign_nonnegative_p (stmt, depth);
     case GIMPLE_CALL:
-      return gimple_call_nonnegative_warnv_p (stmt, strict_overflow_p,
-                                             depth);
+      return gimple_call_nonnegative_p (stmt, depth);
     case GIMPLE_PHI:
       return gimple_phi_nonnegative_p (stmt, depth);
     default:
diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h
index 4b3d5ea4bbc..f1853560779 100644
--- a/gcc/gimple-fold.h
+++ b/gcc/gimple-fold.h
@@ -264,7 +264,7 @@ gimple_build_round_up (gimple_seq *seq, tree type, tree 
old_size,
                                UNKNOWN_LOCATION, type, old_size, align);
 }
 
-extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
+extern bool gimple_stmt_nonnegative_p (gimple *, int = 0);
 extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
 extern void mark_lhs_in_seq_for_dce (bitmap, gimple_seq);
 
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 345b8b54022..1607f737a5a 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -689,9 +689,8 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, 
fur_source &src, tree name)
   // If the result is varying, check for basic nonnegativeness.
   // Specifically this helps for now with strict enum in cases like
   // g++.dg/warn/pr33738.C.
-  bool so_p;
   if (res && r.varying_p () && INTEGRAL_TYPE_P (r.type ())
-      && gimple_stmt_nonnegative_warnv_p (s, &so_p))
+      && gimple_stmt_nonnegative_p (s))
     r.set_nonnegative (r.type ());
 
   if (!res)
@@ -1258,9 +1257,8 @@ fold_using_range::range_of_call (vrange &r, gcall *call, 
fur_source &)
     return false;
 
   tree lhs = gimple_call_lhs (call);
-  bool strict_overflow_p;
 
-  if (gimple_stmt_nonnegative_warnv_p (call, &strict_overflow_p))
+  if (gimple_stmt_nonnegative_p (call))
     r.set_nonnegative (type);
   else if (gimple_call_nonnull_result_p (call)
           || gimple_call_nonnull_arg (call))
-- 
2.43.0

Reply via email to