https://gcc.gnu.org/g:71386cc67c02feff09990b2d9e004810bd3900fd
commit r17-696-g71386cc67c02feff09990b2d9e004810bd3900fd Author: Daniel Barboza <[email protected]> Date: Sat Jan 17 16:01:50 2026 -0300 fold-const.cc: remove strict_overflow_p from tree_unary_nonnegative Similar to what was done with tree_binary_nonnegative_p in the previous patch, we want to remove overflow flags from all tree_unary_nonnegative_warnv_p helpers, and then remove all overflow flags from the parent helper itself. gcc/ChangeLog: * fold-const.cc (tree_unary_nonnegative_warnv_p): Renamed to tree_unary_nonnegative_p. (tree_unary_nonnegative_p): Removed strict_overflow_p flag. (tree_expr_nonnegative_warnv_p): Removed strict_overflow_flag from tree_unary_nonnegative_p calls. * fold-const.h (tree_unary_nonnegative_warnv_p): Renamed to tree_unary_nonnegative_p. (tree_unary_nonnegative_p): Removed strict_overflow_p flag. * gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Removed strict_overflow_flag from tree_unary_nonnegative_p calls. gcc/testsuite/ChangeLog: * gcc.dg/Wstrict-overflow-24.c: Removed since the pattern doesn't throw warnings anymore. * gcc.dg/Wstrict-overflow-9.c: Likewise. Diff: --- gcc/fold-const.cc | 35 +++++++++++++++--------------- gcc/fold-const.h | 3 +-- gcc/gimple-fold.cc | 8 +++---- gcc/testsuite/gcc.dg/Wstrict-overflow-24.c | 10 --------- gcc/testsuite/gcc.dg/Wstrict-overflow-9.c | 10 --------- 5 files changed, 22 insertions(+), 44 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 456f7af97d1e..50f3f9fb58df 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -14604,18 +14604,20 @@ tree_simple_nonnegative_warnv_p (enum tree_code code, tree type) return false; } -/* Return true if (CODE OP0) 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) is known to be non-negative. + DEPTH is the current nesting depth of the query. */ bool -tree_unary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0, - bool *strict_overflow_p, int depth) +tree_unary_nonnegative_p (enum tree_code code, tree type, tree op0, 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 ABS_EXPR: @@ -14624,10 +14626,7 @@ tree_unary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0, if (!ANY_INTEGRAL_TYPE_P (type)) return true; if (TYPE_OVERFLOW_UNDEFINED (type)) - { - *strict_overflow_p = true; - return true; - } + return true; break; case NON_LVALUE_EXPR: @@ -15124,10 +15123,10 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth) depth); case tcc_unary: - return tree_unary_nonnegative_warnv_p (TREE_CODE (t), - TREE_TYPE (t), - TREE_OPERAND (t, 0), - strict_overflow_p, depth); + return tree_unary_nonnegative_p (TREE_CODE (t), + TREE_TYPE (t), + TREE_OPERAND (t, 0), + depth); case tcc_constant: case tcc_declaration: @@ -15149,10 +15148,10 @@ tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth) TREE_OPERAND (t, 1), depth); case TRUTH_NOT_EXPR: - return tree_unary_nonnegative_warnv_p (TREE_CODE (t), - TREE_TYPE (t), - TREE_OPERAND (t, 0), - strict_overflow_p, depth); + return tree_unary_nonnegative_p (TREE_CODE (t), + TREE_TYPE (t), + TREE_OPERAND (t, 0), + depth); case COND_EXPR: case CONSTRUCTOR: diff --git a/gcc/fold-const.h b/gcc/fold-const.h index bdecb5a24d58..8f5d5b69982b 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -165,8 +165,7 @@ extern bool inverse_conditions_p (const_tree, const_tree); extern bool tree_unary_nonzero_p (enum tree_code, tree, tree); 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_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_warnv_p (tree, bool *, int); extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree, diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 88fa15103175..8a06acd8c1f1 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -11449,10 +11449,10 @@ gimple_assign_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p, switch (get_gimple_rhs_class (code)) { case GIMPLE_UNARY_RHS: - return tree_unary_nonnegative_warnv_p (gimple_assign_rhs_code (stmt), - type, - gimple_assign_rhs1 (stmt), - strict_overflow_p, depth); + return tree_unary_nonnegative_p (gimple_assign_rhs_code (stmt), + type, + gimple_assign_rhs1 (stmt), + depth); case GIMPLE_BINARY_RHS: return tree_binary_nonnegative_p (gimple_assign_rhs_code (stmt), type, diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c deleted file mode 100644 index 05e8dd144844..000000000000 --- a/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c +++ /dev/null @@ -1,10 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fstrict-overflow -O2" } */ -/* { dg-message "warnings being treated as errors" "" {target "*-*-*"} 0 } */ -#pragma GCC diagnostic error "-Wstrict-overflow" - -int -foo (int i) -{ - return __builtin_abs (i) >= 0; /* { dg-error "assuming signed overflow does not occur" "correct warning" } */ -} diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-9.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-9.c deleted file mode 100644 index 425a121d5c0a..000000000000 --- a/gcc/testsuite/gcc.dg/Wstrict-overflow-9.c +++ /dev/null @@ -1,10 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow=2" } */ - -/* Source: Ian Lance Taylor. */ - -int -foo (int i) -{ - return __builtin_abs (i) >= 0; /* { dg-warning "assuming signed overflow does not occur" "correct warning" } */ -}
