]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.cc: remove strict_overflow_p from tree_binary_nonnegative
authorDaniel Barboza <daniel.barboza@oss.qualcomm.com>
Sat, 17 Jan 2026 19:01:49 +0000 (16:01 -0300)
committerDaniel Barboza <daniel.barboza@oss.qualcomm.com>
Sat, 23 May 2026 17:20:44 +0000 (14:20 -0300)
We want to remove a fold_overflow_warn() nested inside
tree_exp_nonnegative_warnv_p. This function uses a lot of helpers, and
some of them do recursive calls for the helper itself.

Let's deal with strict_overflow_p flags for each helper first, starting
with tree_binary_nonnegative_warnv_p, that is now renamed to
tree_binary_nonnegative_p since it doesn't handle warnings anymore.

The RECURSE() macro expects a strict_overflow_p variable to be valid in
its scope, so we can't just remove the flag from the function
parameters. We're adding a temporary block that declares a local
strict_overflow_p variable to make RECURSE() happy. These declarations
will all be removed when we deal with tree_expr_nonnegative_warnv_p.

gcc/ChangeLog:

* fold-const.cc (tree_binary_nonnegative_warnv_p): Renamed to
tree_binary_nonnegative_p.
(tree_binary_nonnegative_p): Removed strict_overflow_p flag. Add
a local variable with the same name for RECURSE() that we'll
remove later.
(tree_expr_nonnegative_warnv_p): Removed strict_overflow_p flag
from tree_binary_nonnegative_p call.
* fold-const.h (tree_binary_nonnegative_warnv_p): Renamed to
tree_binary_nonnegative_p.
(tree_binary_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/pr56355-1.c: Removed since it's a warning check test
and we do not emit warnings for the code being tested.

gcc/fold-const.cc
gcc/fold-const.h
gcc/gimple-fold.cc
gcc/testsuite/gcc.dg/pr56355-1.c [deleted file]

index c86327988af1ae0ed277bb6332d0536c172fa55d..456f7af97d1e36395ae83d6050eb9948a10a0b80 100644 (file)
@@ -14670,19 +14670,21 @@ tree_unary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
   return false;
 }
 
-/* Return true if (CODE OP0 OP1) 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 (CODE OP0 OP1) is known to be non-negative.
+   DEPTH is the current nesting depth of the query.  */
 
 bool
-tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
-                                tree op1, bool *strict_overflow_p,
-                                int depth)
+tree_binary_nonnegative_p (enum tree_code code, tree type, tree op0,
+                          tree op1, int depth)
 {
   if (TYPE_UNSIGNED (type))
     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 POINTER_PLUS_EXPR:
@@ -14715,12 +14717,7 @@ tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
             or without overflow.  */
          if (operand_equal_p (op0, op1, 0)
              || (RECURSE (op0) && RECURSE (op1)))
-           {
-             if (ANY_INTEGRAL_TYPE_P (type)
-                 && TYPE_OVERFLOW_UNDEFINED (type))
-               *strict_overflow_p = true;
-             return true;
-           }
+           return true;
        }
 
       /* zero_extend(x) * zero_extend(y) is non-negative if x and y are
@@ -15120,11 +15117,11 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
     {
     case tcc_binary:
     case tcc_comparison:
-      return tree_binary_nonnegative_warnv_p (TREE_CODE (t),
-                                             TREE_TYPE (t),
-                                             TREE_OPERAND (t, 0),
-                                             TREE_OPERAND (t, 1),
-                                             strict_overflow_p, depth);
+      return tree_binary_nonnegative_p (TREE_CODE (t),
+                                       TREE_TYPE (t),
+                                       TREE_OPERAND (t, 0),
+                                       TREE_OPERAND (t, 1),
+                                       depth);
 
     case tcc_unary:
       return tree_unary_nonnegative_warnv_p (TREE_CODE (t),
@@ -15146,11 +15143,11 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth)
     case TRUTH_AND_EXPR:
     case TRUTH_OR_EXPR:
     case TRUTH_XOR_EXPR:
-      return tree_binary_nonnegative_warnv_p (TREE_CODE (t),
-                                             TREE_TYPE (t),
-                                             TREE_OPERAND (t, 0),
-                                             TREE_OPERAND (t, 1),
-                                             strict_overflow_p, depth);
+      return tree_binary_nonnegative_p (TREE_CODE (t),
+                                       TREE_TYPE (t),
+                                       TREE_OPERAND (t, 0),
+                                       TREE_OPERAND (t, 1),
+                                       depth);
     case TRUTH_NOT_EXPR:
       return tree_unary_nonnegative_warnv_p (TREE_CODE (t),
                                             TREE_TYPE (t),
index d6de959c810c1a82ab693c898df02b83490a7271..bdecb5a24d58cecd8d2087b961226cd98c768975 100644 (file)
@@ -167,8 +167,7 @@ extern bool tree_binary_nonzero_p (enum tree_code, tree, tree, tree op1);
 extern bool tree_single_nonzero_p (tree);
 extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree,
                                            bool *, int);
-extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, tree,
-                                            bool *, int);
+extern bool tree_binary_nonnegative_p (enum tree_code, tree, tree, tree, int);
 extern bool tree_single_nonnegative_warnv_p (tree, bool *, int);
 extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree,
                                           bool *, int);
index 6523904425554a243803da94550044d24364c8f1..88fa15103175dd7c689e8f5b5c1641305976465a 100644 (file)
@@ -11454,11 +11454,11 @@ gimple_assign_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
                                             gimple_assign_rhs1 (stmt),
                                             strict_overflow_p, depth);
     case GIMPLE_BINARY_RHS:
-      return tree_binary_nonnegative_warnv_p (gimple_assign_rhs_code (stmt),
-                                             type,
-                                             gimple_assign_rhs1 (stmt),
-                                             gimple_assign_rhs2 (stmt),
-                                             strict_overflow_p, depth);
+      return tree_binary_nonnegative_p (gimple_assign_rhs_code (stmt),
+                                       type,
+                                       gimple_assign_rhs1 (stmt),
+                                       gimple_assign_rhs2 (stmt),
+                                       depth);
     case GIMPLE_TERNARY_RHS:
       return false;
     case GIMPLE_SINGLE_RHS:
diff --git a/gcc/testsuite/gcc.dg/pr56355-1.c b/gcc/testsuite/gcc.dg/pr56355-1.c
deleted file mode 100644 (file)
index 08b9c2e..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O2 -Wstrict-overflow=4" } */
-
-int
-f (int i)
-{
-  return __builtin_abs (i * i); /* { dg-warning "assuming signed overflow" } */
-}