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.
---
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(-)
delete mode 100644 gcc/testsuite/gcc.dg/Wstrict-overflow-24.c
delete mode 100644 gcc/testsuite/gcc.dg/Wstrict-overflow-9.c
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 9fe1cd40650..bd5d8e5a12f 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -14594,18 +14594,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:
@@ -14614,10 +14616,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:
@@ -15109,10 +15108,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:
@@ -15134,10 +15133,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 bdecb5a24d5..8f5d5b69982 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 1ad77322833..333802f4482 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -11402,10 +11402,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 05e8dd14484..00000000000
--- 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 425a121d5c0..00000000000
--- 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" } */
-}
--
2.43.0