On 1/13/2026 10:03 PM, Andrew Pinski wrote:
On Tue, Jan 13, 2026 at 3:16 AM Daniel Barboza
<[email protected]> wrote:
During ML discussions of a match.pd pattern that was introducing a new
instance of 'warn_strict_overflow', Richard mentioned that this use
should be discouraged [1]. After pointing out that this usage was
documented in tree.h he then explained that we should remove the note
from the header [2]. Here's the reasoning:
"Ah, we should remove that note. -Wstrict-overflow proved useless IMO,
it's way too noisy as it diagnoses when the compiler relies on overflow
not happening, not diagnosing when it possibly happens. That's not a
very useful diagnostic to have - it does not point to a possible problem
in the code (we could as well diagnose _all_ signed arithmetic
operations for the same argument that we might eventually rely on
overflow not happening)."
Aside from removing the tree.h node we're also removing the 2 references
in match.pd. match.pd patterns tend to be copied around to serve as a
base for new patterns (like I did in [3] adding a
'fold_overflow_warning'), and if we want to discourage the use avoiding
its spread is a good start.
Note that there are a lot of references left, most of them in
gcc/fold-const.cc. Some references are using in nested helpers inside
the file, entangled with code that does other things. Removing all
references from the project is out of scope for this quick patch.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705320.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705482.html
[3] https://gcc.gnu.org/pipermail/gcc-patches/2026-January/704992.html
gcc/ChangeLog:
* match.pd: remove 'fold_overflow_warning' references.
* tree.h (TYPE_OVERFLOW_UNDEFINED): remove note telling
that we must use warn_strict_overflow for every optimization
based on TYPE_OVERFLOW_UNDEFINED.
Signed-off-by: Daniel Barboza <[email protected]>
---
gcc/match.pd | 12 +-----------
gcc/testsuite/gcc.dg/Wstrict-overflow-1.c | 13 -------------
Since you are doing some cleanup with respect to -Wstrict-overflow.
You want to handle https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80511
?
In that bug report case I think it is only the testcases that need to
be cleaned up.
I'll look into it. Thanks,
Daniel
Thanks,
Andrew
gcc/tree.h | 8 +-------
3 files changed, 2 insertions(+), 31 deletions(-)
delete mode 100644 gcc/testsuite/gcc.dg/Wstrict-overflow-1.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 08d0810e986..a06a26a93d7 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9824,9 +9824,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(with { tree res = int_const_binop (rop, @2, @1); }
(if (TREE_OVERFLOW (res))
{
- fold_overflow_warning (("assuming signed overflow does not occur "
- "when simplifying conditional to constant"),
- WARN_STRICT_OVERFLOW_CONDITIONAL);
bool less = cmp == LE_EXPR || cmp == LT_EXPR;
/* wi::ges_p (@2, 0) should be sufficient for a signed type. */
bool ovf_high = wi::lt_p (wi::to_wide (@1), 0,
@@ -9835,14 +9832,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
constant_boolean_node (less == ovf_high, type);
}
(if (single_use (@3))
- (with
- {
- fold_overflow_warning (("assuming signed overflow does not occur "
- "when changing X +- C1 cmp C2 to "
- "X cmp C2 -+ C1"),
- WARN_STRICT_OVERFLOW_COMPARISON);
- }
- (cmp @0 { res; })))))
+ (cmp @0 { res; }))))
/* For wrapping types, simplify the following cases of X +- C1 CMP C2:
(a) If CMP is <= and C2 -+ C1 == +INF (1), simplify to X >= -INF -+ C1
diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-1.c
b/gcc/testsuite/gcc.dg/Wstrict-overflow-1.c
deleted file mode 100644
index 068bfe49446..00000000000
--- a/gcc/testsuite/gcc.dg/Wstrict-overflow-1.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow=3" } */
-
-/* Source: Ian Lance Taylor. Based on strict-overflow-1.c. */
-
-/* We can only simplify the conditional when using strict overflow
- semantics. */
-
-int
-foo (int i)
-{
- return i - 5 < 10; /* { dg-warning "assuming signed overflow does not occur"
"correct warning" } */
-}
diff --git a/gcc/tree.h b/gcc/tree.h
index 120f37ba0db..1adc66336d3 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -974,13 +974,7 @@ extern void omp_clause_range_check_failed (const_tree,
const char *, int,
|| flag_wrapv))
/* True if overflow is undefined for the given integral or pointer type.
- We may optimize on the assumption that values in the type never overflow.
-
- IMPORTANT NOTE: Any optimization based on TYPE_OVERFLOW_UNDEFINED
- must issue a warning based on warn_strict_overflow. In some cases
- it will be appropriate to issue the warning immediately, and in
- other cases it will be appropriate to simply set a flag and let the
- caller decide whether a warning is appropriate or not. */
+ We may optimize on the assumption that values in the type never overflow.
*/
#define TYPE_OVERFLOW_UNDEFINED(TYPE) \
(POINTER_TYPE_P (TYPE) \
? !flag_wrapv_pointer \
--
2.43.0