aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-ccp.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-02-13 22:34:45 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2007-02-13 22:34:45 +0000
commit6ac015100fa98539d577a6c04b69693aefce35dc (patch)
tree120377355d73c96495ca9008ae2e8dd5c40948af /gcc/tree-ssa-ccp.c
parent30d18db4847eb0995d65531e117c7fe75d1fc428 (diff)
downloadgcc-6ac015100fa98539d577a6c04b69693aefce35dc.zip
gcc-6ac015100fa98539d577a6c04b69693aefce35dc.tar.gz
gcc-6ac015100fa98539d577a6c04b69693aefce35dc.tar.bz2
common.opt: Add Wstrict-overflow and Wstrict-overflow=.
./: * common.opt: Add Wstrict-overflow and Wstrict-overflow=. * flags.h (warn_strict_overflow): Declare. (enum warn_strict_overflow_code): Define. (issue_strict_overflow_warning): New static inline function. * opts.c (warn_strict_overflow): New variable. (common_handle_option): Handle OPT_Wstrict_overflow and OPT_Wstrict_overflow_. * c-opts.c (c_common_handle_option): Set warn_strict_overflow for OPT_Wall. * fold-const.c: Include intl.h. (fold_deferring_overflow_warnings): New static variable. (fold_deferred_overflow_warning): New static variable. (fold_deferred_overflow_code): New static variable. (fold_defer_overflow_warnings): New function. (fold_undefer_overflow_warnings): New function. (fold_undefer_and_ignore_overflow_warnings): New function. (fold_deferring_overflow_warnings_p): New function. (fold_overflow_warning): New static function. (make_range): Add strict_overflow_p parameter. Change all callers. (extract_muldiv, extract_muldiv_1): Likewise. (fold_unary) [ABS_EXPR]: Check ABS_EXPR before calling tree_expr_nonnegative_p. (fold_negate_expr): Call fold_overflow_warning. (fold_range_test): Likewise. (fold_comparison): Likewise. (fold_binary): Likewise. Call tree_expr_nonnegative_warnv_p instead of tree_expr_nonnegative_p. (tree_expr_nonnegative_warnv_p): Rename from tree_expr_nonnegative_p, add strict_overflow_p parameter. (tree_expr_nonnegative_p): New function. (tree_expr_nonzero_warnv_p): Rename from tree_expr_nonzero_p, add strict_overflow_p parameter. (tree_expr_nonzero_p): New function. * passes.c (verify_interpass_invariants): New static function. (execute_one_pass): Call it. * tree-ssa-loop-niter.c (expand_simple_operations): Ignore fold warnings. (number_of_iterations_exit, loop_niter_by_eval): Likewise. (estimate_numbers_of_iterations): Likewise. (scev_probably_wraps_p): Likewise. * tree-ssa-ccp.c: Include "toplev.h". (evaluate_stmt): Defer fold overflow warnings until we know we are going to optimize. (struct fold_stmt_r_data): Add stmt field. (fold_stmt_r): Defer fold overflow warnings until we know we optimized. (fold_stmt): Initialize stmt field of fold_stmt_r_data. (fold_stmt_inplace): Likewise. * tree-cfgcleanup.c: Include "toplev.h" rather than "errors.h". (cleanup_control_expr_graph): Defer fold overflow warnings until we know we are going to optimize. * tree-cfg.c (fold_cond_expr_cond): Likewise. * tree-ssa-threadedge.c (simplify_control_stmt_condition): Likewise. * tree-vrp.c (vrp_expr_computes_nonnegative): Call tree_expr_nonnegative_warnv_p instead of tree_expr_nonnegative_p. * tree-ssa-loop-manip.c (create_iv): Likewise. * c-typeck.c (build_conditional_expr): Likewise. (build_binary_op): Likewise. * tree-vrp.c (vrp_expr_computes_nonzero): Call tree_expr_nonzero_warnv_p instead of tree_expr_nonzero_p. (extract_range_from_unary_expr): Likewise. * simplify-rtx.c (simplify_const_relational_operation): Warn when assuming that signed overflow does not occur. * c-common.c (pointer_int_sum): Ignore fold overflow warnings. * tree.h (tree_expr_nonnegative_warnv_p): Declare. (fold_defer_overflow_warnings): Declare. (fold_undefer_overflow_warnings): Declare. (fold_undefer_and_ignore_overflow_warnings): Declare. (fold_deferring_overflow_warnings_p): Declare. (tree_expr_nonzero_warnv_p): Declare. * doc/invoke.texi (Option Summary): Add -Wstrict-overflow to list of warning options. (Warning Options): Document -Wstrict-overflow. * Makefile.in (tree-ssa-threadedge.o): Depend on toplev.h. (tree-ssa-ccp.o): Likewise. (tree-cfgcleanup.o): Change errors.h dependency to toplev.h. (fold-const.o): Depend on intl.h. testsuite/: * gcc.dg/Wstrict-overflow-1.c: New test. * gcc.dg/Wstrict-overflow-2.c: New test. * gcc.dg/Wstrict-overflow-3.c: New test. * gcc.dg/Wstrict-overflow-4.c: New test. * gcc.dg/Wstrict-overflow-5.c: New test. * gcc.dg/Wstrict-overflow-6.c: New test. * gcc.dg/Wstrict-overflow-7.c: New test. * gcc.dg/Wstrict-overflow-8.c: New test. * gcc.dg/Wstrict-overflow-9.c: New test. * gcc.dg/Wstrict-overflow-10.c: New test. From-SVN: r121895
Diffstat (limited to 'gcc/tree-ssa-ccp.c')
-rw-r--r--gcc/tree-ssa-ccp.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index b6c3599..459894b 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -1,5 +1,5 @@
/* Conditional constant propagation pass for the GNU compiler.
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
Adapted from original RTL SSA-CCP by Daniel Berlin <dberlin@dberlin.org>
Adapted to GIMPLE trees by Diego Novillo <dnovillo@redhat.com>
@@ -207,6 +207,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
#include "tree-ssa-propagate.h"
#include "langhooks.h"
#include "target.h"
+#include "toplev.h"
/* Possible lattice values. */
@@ -1132,9 +1133,12 @@ evaluate_stmt (tree stmt)
prop_value_t val;
tree simplified = NULL_TREE;
ccp_lattice_t likelyvalue = likely_value (stmt);
+ bool is_constant;
val.mem_ref = NULL_TREE;
+ fold_defer_overflow_warnings ();
+
/* If the statement is likely to have a CONSTANT result, then try
to fold the statement to determine the constant value. */
if (likelyvalue == CONSTANT)
@@ -1151,7 +1155,11 @@ evaluate_stmt (tree stmt)
else if (!simplified)
simplified = fold_const_aggregate_ref (get_rhs (stmt));
- if (simplified && is_gimple_min_invariant (simplified))
+ is_constant = simplified && is_gimple_min_invariant (simplified);
+
+ fold_undefer_overflow_warnings (is_constant, stmt, 0);
+
+ if (is_constant)
{
/* The statement produced a constant value. */
val.lattice_val = CONSTANT;
@@ -1966,8 +1974,9 @@ maybe_fold_stmt_addition (tree expr)
struct fold_stmt_r_data
{
- bool *changed_p;
- bool *inside_addr_expr_p;
+ tree stmt;
+ bool *changed_p;
+ bool *inside_addr_expr_p;
};
/* Subroutine of fold_stmt called via walk_tree. We perform several
@@ -2063,10 +2072,16 @@ fold_stmt_r (tree *expr_p, int *walk_subtrees, void *data)
if (COMPARISON_CLASS_P (TREE_OPERAND (expr, 0)))
{
tree op0 = TREE_OPERAND (expr, 0);
- tree tem = fold_binary (TREE_CODE (op0), TREE_TYPE (op0),
- TREE_OPERAND (op0, 0),
- TREE_OPERAND (op0, 1));
- if (tem && set_rhs (expr_p, tem))
+ tree tem;
+ bool set;
+
+ fold_defer_overflow_warnings ();
+ tem = fold_binary (TREE_CODE (op0), TREE_TYPE (op0),
+ TREE_OPERAND (op0, 0),
+ TREE_OPERAND (op0, 1));
+ set = tem && set_rhs (expr_p, tem);
+ fold_undefer_overflow_warnings (set, fold_stmt_r_data->stmt, 0);
+ if (set)
{
t = *expr_p;
break;
@@ -2373,11 +2388,12 @@ fold_stmt (tree *stmt_p)
bool changed = false;
bool inside_addr_expr = false;
+ stmt = *stmt_p;
+
+ fold_stmt_r_data.stmt = stmt;
fold_stmt_r_data.changed_p = &changed;
fold_stmt_r_data.inside_addr_expr_p = &inside_addr_expr;
- stmt = *stmt_p;
-
/* If we replaced constants and the statement makes pointer dereferences,
then we may need to fold instances of *&VAR into VAR, etc. */
if (walk_tree (stmt_p, fold_stmt_r, &fold_stmt_r_data, NULL))
@@ -2472,6 +2488,7 @@ fold_stmt_inplace (tree stmt)
bool changed = false;
bool inside_addr_expr = false;
+ fold_stmt_r_data.stmt = stmt;
fold_stmt_r_data.changed_p = &changed;
fold_stmt_r_data.inside_addr_expr_p = &inside_addr_expr;