https://gcc.gnu.org/g:ab8cd1385e70f8e445d239b88a8ca514d70f2de8
commit r17-695-gab8cd1385e70f8e445d239b88a8ca514d70f2de8 Author: Daniel Barboza <[email protected]> Date: Sat Jan 17 16:01:49 2026 -0300 fold-const.cc: remove strict_overflow_p from tree_binary_nonnegative 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. Diff: --- gcc/fold-const.cc | 43 +++++++++++++++++++--------------------- gcc/fold-const.h | 3 +-- gcc/gimple-fold.cc | 10 +++++----- gcc/testsuite/gcc.dg/pr56355-1.c | 8 -------- 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index c86327988af1..456f7af97d1e 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -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), diff --git a/gcc/fold-const.h b/gcc/fold-const.h index d6de959c810c..bdecb5a24d58 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -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); diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 652390442555..88fa15103175 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -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 index 08b9c2e7109b..000000000000 --- a/gcc/testsuite/gcc.dg/pr56355-1.c +++ /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" } */ -}
