]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.cc: remove strict_overflow flag from make_range helpers
authorDaniel Barboza <daniel.barboza@oss.qualcomm.com>
Sat, 17 Jan 2026 19:01:42 +0000 (16:01 -0300)
committerDaniel Barboza <daniel.barboza@oss.qualcomm.com>
Sat, 23 May 2026 17:20:43 +0000 (14:20 -0300)
This is a first step towards deprecating -Wstrict_overflow. The warning
is rooted in several places throughout the code, fold-const.cc functions
being one of them (via fold_overload_warn()).

These helpers are used in other files as well so the approach taken is to
gradually remove it from fold-const.cc while fixing the existing callers
along the way.

gcc/c-family/ChangeLog:

* c-warn.cc (warn_logical_operator): Removed strict_overflow_p
variable.

gcc/ChangeLog:

* fold-const.cc (make_range_step): Likewise.
(make_range): Likewise.
(fold_range_test): Likewise.
* fold-const.h (make_range): Likewise.
(make_range_step): Likewise.
* tree-ssa-reassoc.cc (init_range_entry): Likewise.

gcc/c-family/c-warn.cc
gcc/fold-const.cc
gcc/fold-const.h
gcc/tree-ssa-reassoc.cc

index 6de072582dfcd79b2e73a0dce329ce5c23d0506e..e956fae51caf957b9276a0f7774fb97b1e6be89b 100644 (file)
@@ -189,7 +189,6 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
   int or_op = (code == TRUTH_ORIF_EXPR || code == TRUTH_OR_EXPR);
   int in0_p, in1_p, in_p;
   tree low0, low1, low, high0, high1, high, lhs, rhs, tem;
-  bool strict_overflow_p = false;
 
   if (!warn_logical_op)
     return;
@@ -264,7 +263,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
      portable code.  */
   op_left = unshare_expr (op_left);
   walk_tree_without_duplicates (&op_left, unwrap_c_maybe_const, NULL);
-  lhs = make_range (op_left, &in0_p, &low0, &high0, &strict_overflow_p);
+  lhs = make_range (op_left, &in0_p, &low0, &high0);
   if (!lhs)
     return;
 
@@ -279,7 +278,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
 
   op_right = unshare_expr (op_right);
   walk_tree_without_duplicates (&op_right, unwrap_c_maybe_const, NULL);
-  rhs = make_range (op_right, &in1_p, &low1, &high1, &strict_overflow_p);
+  rhs = make_range (op_right, &in1_p, &low1, &high1);
   if (!rhs)
     return;
 
index 99056543a04b8d33c27c21abd630eb3b3543ccff..891adc9d89fbd481e3fdf92aedbc480241b8c179 100644 (file)
@@ -5245,8 +5245,7 @@ range_binop (enum tree_code code, tree type, tree arg0, int upper0_p,
 
 tree
 make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1,
-                tree exp_type, tree *p_low, tree *p_high, int *p_in_p,
-                bool *strict_overflow_p)
+                tree exp_type, tree *p_low, tree *p_high, int *p_in_p)
 {
   tree arg0_type = TREE_TYPE (arg0);
   tree n_low, n_high, low = *p_low, high = *p_high;
@@ -5381,9 +5380,6 @@ make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1,
          || (n_high != 0 && TREE_OVERFLOW (n_high)))
        return NULL_TREE;
 
-      if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
-       *strict_overflow_p = true;
-
       normalize:
        /* Check for an unsigned range which has wrapped around the maximum
           value thus making n_high < n_low, and normalize it.  */
@@ -5535,14 +5531,10 @@ make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1,
    variables denoted by PIN_P, PLOW, and PHIGH.  Return the expression
    actually being tested.  *PLOW and *PHIGH will be made of the same
    type as the returned expression.  If EXP is not a comparison, we
-   will most likely not be returning a useful value and range.  Set
-   *STRICT_OVERFLOW_P to true if the return value is only valid
-   because signed overflow is undefined; otherwise, do not change
-   *STRICT_OVERFLOW_P.  */
+   will most likely not be returning a useful value and range.  */
 
 tree
-make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
-           bool *strict_overflow_p)
+make_range (tree exp, int *pin_p, tree *plow, tree *phigh)
 {
   enum tree_code code;
   tree arg0, arg1 = NULL_TREE;
@@ -5580,7 +5572,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
        break;
 
       nexp = make_range_step (loc, code, arg0, arg1, exp_type, &low,
-                             &high, &in_p, strict_overflow_p);
+                             &high, &in_p);
       if (nexp == NULL_TREE)
        break;
       exp = nexp;
@@ -6277,15 +6269,12 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
               || code == TRUTH_OR_EXPR);
   int in0_p, in1_p, in_p;
   tree low0, low1, low, high0, high1, high;
-  bool strict_overflow_p = false;
   tree tem, lhs, rhs;
-  const char * const warnmsg = G_("assuming signed overflow does not occur "
-                                 "when simplifying range test");
 
   if (!INTEGRAL_TYPE_P (type))
     return 0;
 
-  lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
+  lhs = make_range (op0, &in0_p, &low0, &high0);
   /* If op0 is known true or false and this is a short-circuiting
      operation we must not merge with op1 since that makes side-effects
      unconditional.  So special-case this.  */
@@ -6293,7 +6282,7 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
       && ((code == TRUTH_ORIF_EXPR && in0_p)
          || (code == TRUTH_ANDIF_EXPR && !in0_p)))
     return op0;
-  rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
+  rhs = make_range (op1, &in1_p, &low1, &high1);
 
   /* If this is an OR operation, invert both sides; we will invert
      again at the end.  */
@@ -6312,8 +6301,6 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
                                    : rhs != 0 ? rhs : integer_zero_node,
                                    in_p, low, high))) != 0)
     {
-      if (strict_overflow_p)
-       fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON);
       return or_op ? invert_truthvalue_loc (loc, tem) : tem;
     }
 
@@ -6350,9 +6337,6 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
                                           or_op ? ! in1_p : in1_p,
                                           low1, high1)) != 0)
            {
-             if (strict_overflow_p)
-               fold_overflow_warning (warnmsg,
-                                      WARN_STRICT_OVERFLOW_COMPARISON);
              return build2_loc (loc, code == TRUTH_ANDIF_EXPR
                                 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
                                 type, lhs, rhs);
index 373031477735aa4273445d81e7767f179c41c71d..49d481398a7790c1bf6d6be8d4b6046123266f72 100644 (file)
@@ -213,9 +213,9 @@ extern bool tree_expr_maybe_signaling_nan_p (const_tree);
 extern bool tree_expr_nan_p (const_tree);
 extern bool tree_expr_maybe_nan_p (const_tree);
 extern bool tree_expr_maybe_real_minus_zero_p (const_tree);
-extern tree make_range (tree, int *, tree *, tree *, bool *);
+extern tree make_range (tree, int *, tree *, tree *);
 extern tree make_range_step (location_t, enum tree_code, tree, tree, tree,
-                            tree *, tree *, int *, bool *);
+                            tree *, tree *, int *);
 extern tree range_check_type (tree);
 extern tree build_range_check (location_t, tree, tree, int, tree, tree);
 extern bool merge_ranges (int *, tree *, tree *, int, tree, tree, int,
index 7abbf195520bc6c93015bc11bda14e0b6aa97507..db6f7118d2cc6c8fa353c755b12c138f3c230786 100644 (file)
@@ -2660,8 +2660,7 @@ init_range_entry (struct range_entry *r, tree exp, gimple *stmt)
            return;
        do_default:
          nexp = make_range_step (loc, code, arg0, arg1, exp_type,
-                                 &low, &high, &in_p,
-                                 &strict_overflow_p);
+                                 &low, &high, &in_p);
          if (nexp != NULL_TREE)
            {
              exp = nexp;