aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorKazu Hirata <kazu@cs.umass.edu>2005-05-02 18:06:27 +0000
committerKazu Hirata <kazu@gcc.gnu.org>2005-05-02 18:06:27 +0000
commitfda05890956b883a25ea35edfa65db76a50c3da3 (patch)
tree007185f8315d22ba9507e23cada2994174208884 /gcc/tree-vrp.c
parentcbbf94032814561e9fbc7a5330b73d77bbcaa8ed (diff)
downloadgcc-fda05890956b883a25ea35edfa65db76a50c3da3.zip
gcc-fda05890956b883a25ea35edfa65db76a50c3da3.tar.gz
gcc-fda05890956b883a25ea35edfa65db76a50c3da3.tar.bz2
re PR tree-optimization/21294 (Missed removal of null pointer check)
gcc/ PR tree-optimization/21294 * tree-vrp.c (vrp_expr_computes_nonzero): New. (extract_range_from_expr): Call vrp_expr_computes_nonzero. testsuite/ PR tree-optimization/21294 * gcc.dg/tree-ssa/pr21294.c: New. From-SVN: r99111
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 0fe5c7b..e6cb017 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -717,6 +717,35 @@ extract_range_from_binary_expr (value_range *vr, tree expr)
}
+/* Like expr_computes_nonzero, but this function uses value ranges
+ obtained so far. */
+
+static bool
+vrp_expr_computes_nonzero (tree expr)
+{
+ if (expr_computes_nonzero (expr))
+ return true;
+
+ /* If we have an expression of the form &X->a, then the expression
+ is nonnull if X is nonnull. */
+ if (TREE_CODE (expr) == ADDR_EXPR)
+ {
+ tree base = get_base_address (TREE_OPERAND (expr, 0));
+
+ if (base != NULL_TREE
+ && TREE_CODE (base) == INDIRECT_REF
+ && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
+ {
+ value_range *vr = get_value_range (TREE_OPERAND (base, 0));
+ if (range_is_nonnull (vr))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
/* Extract range information from a unary expression EXPR based on
the range of its operand and the expression code. */
@@ -833,7 +862,7 @@ extract_range_from_expr (value_range *vr, tree expr)
extract_range_from_binary_expr (vr, expr);
else if (TREE_CODE_CLASS (code) == tcc_unary)
extract_range_from_unary_expr (vr, expr);
- else if (expr_computes_nonzero (expr))
+ else if (vrp_expr_computes_nonzero (expr))
set_value_range_to_nonnull (vr, TREE_TYPE (expr));
else if (TREE_CODE (expr) == INTEGER_CST)
set_value_range (vr, VR_RANGE, expr, expr);