https://gcc.gnu.org/g:3b65feed776df4c79a958406ad1bd25aeb08b38e
commit r17-688-g3b65feed776df4c79a958406ad1bd25aeb08b38e Author: Daniel Barboza <[email protected]> Date: Sat Jan 17 16:01:42 2026 -0300 fold-const.cc: remove strict_overflow flag from make_range helpers 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. Diff: --- gcc/c-family/c-warn.cc | 5 ++--- gcc/fold-const.cc | 28 ++++++---------------------- gcc/fold-const.h | 4 ++-- gcc/tree-ssa-reassoc.cc | 3 +-- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 6de072582dfc..e956fae51caf 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -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; diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 99056543a04b..891adc9d89fb 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -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); diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 373031477735..49d481398a77 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -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, diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 7abbf195520b..db6f7118d2cc 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -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;
