diff options
author | Roger Sayle <roger@eyesopen.com> | 2004-07-04 18:41:05 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2004-07-04 18:41:05 +0000 |
commit | 06a9b53f08369e3d1a88af7461685fca40519514 (patch) | |
tree | b09498ce8cf001c12d71dcc6b23c6d3c16bf3ca4 | |
parent | 43da93a7281a7c66c0ae23abdf9e501c4b5bbd88 (diff) | |
download | gcc-06a9b53f08369e3d1a88af7461685fca40519514.zip gcc-06a9b53f08369e3d1a88af7461685fca40519514.tar.gz gcc-06a9b53f08369e3d1a88af7461685fca40519514.tar.bz2 |
tree-ssa-ccp.c (set_rhs): Change function to return a bool.
* tree-ssa-ccp.c (set_rhs): Change function to return a bool.
Ensure the replacement rhs is valid gimple before performing
the substitution. Return false if these sanity checks fail.
(fold_stmt): Only set changed to true, if set_rhs returns true.
(execute_fold_all_builtins): Only call modify_stmt if set_rhs
succeeds.
From-SVN: r84091
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/tree-ssa-ccp.c | 33 |
2 files changed, 32 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 86ebbf5..a4d210c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-07-04 Roger Sayle <roger@eyesopen.com> + + * tree-ssa-ccp.c (set_rhs): Change function to return a bool. + Ensure the replacement rhs is valid gimple before performing + the substitution. Return false if these sanity checks fail. + (fold_stmt): Only set changed to true, if set_rhs returns true. + (execute_fold_all_builtins): Only call modify_stmt if set_rhs + succeeds. + 2004-07-04 Richard Henderson <rth@redhat.com> PR c/16348 diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 0b99071..70b91f2 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 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2004 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> @@ -141,7 +141,7 @@ static void dump_lattice_value (FILE *, const char *, value); static bool replace_uses_in (tree, bool *); static latticevalue likely_value (tree); static tree get_rhs (tree); -static void set_rhs (tree *, tree); +static bool set_rhs (tree *, tree); static value *get_value (tree); static value get_default_value (tree); static tree ccp_fold_builtin (tree, tree); @@ -2089,10 +2089,7 @@ fold_stmt (tree *stmt_p) STRIP_USELESS_TYPE_CONVERSION (result); if (result != rhs) - { - changed = true; - set_rhs (stmt_p, result); - } + changed |= set_rhs (stmt_p, result); return changed; } @@ -2130,12 +2127,26 @@ get_rhs (tree stmt) /* Set the main expression of *STMT_P to EXPR. */ -static void +static bool set_rhs (tree *stmt_p, tree expr) { tree stmt = *stmt_p; - enum tree_code code = TREE_CODE (stmt); + enum tree_code code = TREE_CODE (expr); + /* Verify the constant folded result is valid gimple. */ + if (TREE_CODE_CLASS (code) == '2') + { + if (!is_gimple_val (TREE_OPERAND (expr, 0)) + || !is_gimple_val (TREE_OPERAND (expr, 1))) + return false; + } + else if (TREE_CODE_CLASS (code) == '1') + { + if (!is_gimple_val (TREE_OPERAND (expr, 0))) + return false; + } + + code = TREE_CODE (stmt); if (code == MODIFY_EXPR) TREE_OPERAND (stmt, 1) = expr; else if (code == COND_EXPR) @@ -2196,6 +2207,8 @@ set_rhs (tree *stmt_p, tree expr) } } } + + return true; } @@ -2510,8 +2523,8 @@ execute_fold_all_builtins (void) print_generic_stmt (dump_file, *stmtp, dump_flags); } - set_rhs (stmtp, result); - modify_stmt (*stmtp); + if (set_rhs (stmtp, result)) + modify_stmt (*stmtp); if (dump_file && (dump_flags & TDF_DETAILS)) { |