From 73aac82287a46d9b479c72a78672b2593e610ad5 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 21 May 2020 13:19:18 -0400 Subject: [PATCH 173/179] FIXME: remove redundant checks for NULL in region_model2::eval_condition_without_cm --- gcc/analyzer/region-model2.cc | 122 +++++++++++++++++----------------- 1 file changed, 60 insertions(+), 62 deletions(-) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index a0ed2078451..3f19bc37a6b 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -5793,81 +5793,79 @@ region_model2::eval_condition_without_cm (const svalue2 *lhs, gcc_assert (rhs); /* See what we know based on the values. */ - if (lhs && rhs) - { - /* For now, make no attempt to capture constraints on floating-point - values. */ - if ((lhs->get_type () && FLOAT_TYPE_P (lhs->get_type ())) - || (rhs->get_type () && FLOAT_TYPE_P (rhs->get_type ()))) - return tristate::unknown (); - if (lhs == rhs) + /* For now, make no attempt to capture constraints on floating-point + values. */ + if ((lhs->get_type () && FLOAT_TYPE_P (lhs->get_type ())) + || (rhs->get_type () && FLOAT_TYPE_P (rhs->get_type ()))) + return tristate::unknown (); + + if (lhs == rhs) + { + /* If we have the same svalue2, then we have equality + (apart from NaN-handling). + TODO: should this definitely be the case for poisoned values? */ + switch (op) { - /* If we have the same svalue2, then we have equality - (apart from NaN-handling). - TODO: should this definitely be the case for poisoned values? */ - switch (op) - { - case EQ_EXPR: - case GE_EXPR: - case LE_EXPR: - return tristate::TS_TRUE; - - case NE_EXPR: - case GT_EXPR: - case LT_EXPR: - return tristate::TS_FALSE; - - default: - /* For other ops, use the logic below. */ - break; - } + case EQ_EXPR: + case GE_EXPR: + case LE_EXPR: + return tristate::TS_TRUE; + + case NE_EXPR: + case GT_EXPR: + case LT_EXPR: + return tristate::TS_FALSE; + + default: + /* For other ops, use the logic below. */ + break; } + } - /* If we have a pair of region_svalue2s, compare them. */ - if (const region_svalue2 *lhs_ptr = lhs->dyn_cast_region_svalue2 ()) - if (const region_svalue2 *rhs_ptr = rhs->dyn_cast_region_svalue2 ()) - { - tristate res = region_svalue2::eval_condition (lhs_ptr, op, rhs_ptr); - if (res.is_known ()) - return res; - /* Otherwise, only known through constraints. */ - } + /* If we have a pair of region_svalue2s, compare them. */ + if (const region_svalue2 *lhs_ptr = lhs->dyn_cast_region_svalue2 ()) + if (const region_svalue2 *rhs_ptr = rhs->dyn_cast_region_svalue2 ()) + { + tristate res = region_svalue2::eval_condition (lhs_ptr, op, rhs_ptr); + if (res.is_known ()) + return res; + /* Otherwise, only known through constraints. */ + } - /* If we have a pair of constants, compare them. */ - if (const constant_svalue2 *cst_lhs = lhs->dyn_cast_constant_svalue2 ()) - if (const constant_svalue2 *cst_rhs = rhs->dyn_cast_constant_svalue2 ()) - return constant_svalue2::eval_condition (cst_lhs, op, cst_rhs); + /* If we have a pair of constants, compare them. */ + if (const constant_svalue2 *cst_lhs = lhs->dyn_cast_constant_svalue2 ()) + if (const constant_svalue2 *cst_rhs = rhs->dyn_cast_constant_svalue2 ()) + return constant_svalue2::eval_condition (cst_lhs, op, cst_rhs); - /* Handle comparison of a region_svalue2 against zero. */ + /* Handle comparison of a region_svalue2 against zero. */ - if (const region_svalue2 *ptr = lhs->dyn_cast_region_svalue2 ()) - if (const constant_svalue2 *cst_rhs = rhs->dyn_cast_constant_svalue2 ()) - if (zerop (cst_rhs->get_constant ())) + if (const region_svalue2 *ptr = lhs->dyn_cast_region_svalue2 ()) + if (const constant_svalue2 *cst_rhs = rhs->dyn_cast_constant_svalue2 ()) + if (zerop (cst_rhs->get_constant ())) + { + /* A region_svalue2 is a non-NULL pointer, except in certain + special cases (see the comment for region2::non_null_p. */ + const region2 *pointee = ptr->get_pointee (); + if (pointee->non_null_p (*this)) { - /* A region_svalue2 is a non-NULL pointer, except in certain - special cases (see the comment for region2::non_null_p. */ - const region2 *pointee = ptr->get_pointee (); - if (pointee->non_null_p (*this)) + switch (op) { - switch (op) - { - default: - gcc_unreachable (); + default: + gcc_unreachable (); - case EQ_EXPR: - case GE_EXPR: - case LE_EXPR: - return tristate::TS_FALSE; + case EQ_EXPR: + case GE_EXPR: + case LE_EXPR: + return tristate::TS_FALSE; - case NE_EXPR: - case GT_EXPR: - case LT_EXPR: - return tristate::TS_TRUE; - } + case NE_EXPR: + case GT_EXPR: + case LT_EXPR: + return tristate::TS_TRUE; } } - } + } return tristate::TS_UNKNOWN; } -- 2.21.0