From 398a5777e520e6a813009b5db4495f4b59526694 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 18 Jun 2020 06:59:58 -0400 Subject: [PATCH 235/315] FIXME: simplify signature of range2::constrained_to_single_element --- gcc/analyzer/constraint-manager2.cc | 29 +++++++++++------------------ gcc/analyzer/constraint-manager2.h | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/gcc/analyzer/constraint-manager2.cc b/gcc/analyzer/constraint-manager2.cc index 15e47964bb7..328321d2cc6 100644 --- a/gcc/analyzer/constraint-manager2.cc +++ b/gcc/analyzer/constraint-manager2.cc @@ -145,20 +145,19 @@ range2::dump () const } /* Determine if there is only one possible value for this range2. - If so, return true and write the constant to *OUT. - Otherwise, return false. */ + If so, return the constant; otherwise, return NULL_TREE. */ -bool -range2::constrained_to_single_element (tree *out) +tree +range2::constrained_to_single_element () { if (m_lower_bound.m_constant == NULL_TREE || m_upper_bound.m_constant == NULL_TREE) - return false; + return NULL_TREE; if (!INTEGRAL_TYPE_P (TREE_TYPE (m_lower_bound.m_constant))) - return false; + return NULL_TREE; if (!INTEGRAL_TYPE_P (TREE_TYPE (m_upper_bound.m_constant))) - return false; + return NULL_TREE; /* Convert any open bounds to closed bounds. */ m_lower_bound.ensure_closed (false); @@ -169,12 +168,9 @@ range2::constrained_to_single_element (tree *out) m_lower_bound.m_constant, m_upper_bound.m_constant); if (comparison == boolean_true_node) - { - *out = m_lower_bound.m_constant; - return true; - } + return m_lower_bound.m_constant; else - return false; + return NULL_TREE; } /* Eval the condition "X OP RHS_CONST" for X within the range. */ @@ -184,8 +180,7 @@ range2::eval_condition (enum tree_code op, tree rhs_const) const { range2 copy (*this); - tree single_element; - if (copy.constrained_to_single_element (&single_element)) + if (tree single_element = copy.constrained_to_single_element ()) return compare_constants (single_element, op, rhs_const); switch (op) @@ -963,8 +958,7 @@ constraint_manager2::add_constraint_internal (equiv_class2_id lhs_id, range2 r (bound2 (lhs_const, c_op == CONSTRAINT2_LE), bound2 (other_rhs_const, other->m_op == CONSTRAINT2_LE)); - tree constant; - if (r.constrained_to_single_element (&constant)) + if (tree constant = r.constrained_to_single_element ()) { const svalue2 *cst_sval = m_mgr->get_or_create_constant_svalue2 (constant); @@ -996,8 +990,7 @@ constraint_manager2::add_constraint_internal (equiv_class2_id lhs_id, other->m_op == CONSTRAINT2_LE), bound2 (rhs_const, c_op == CONSTRAINT2_LE)); - tree constant; - if (r.constrained_to_single_element (&constant)) + if (tree constant = r.constrained_to_single_element ()) { const svalue2 *cst_sval = m_mgr->get_or_create_constant_svalue2 (constant); diff --git a/gcc/analyzer/constraint-manager2.h b/gcc/analyzer/constraint-manager2.h index 13c2b5d3cc5..b6cc0aef6fe 100644 --- a/gcc/analyzer/constraint-manager2.h +++ b/gcc/analyzer/constraint-manager2.h @@ -53,7 +53,7 @@ struct range2 void dump_to_pp (pretty_printer *pp) const; void dump () const; - bool constrained_to_single_element (tree *out); + tree constrained_to_single_element (); tristate eval_condition (enum tree_code op, tree rhs_const) const; -- 2.26.2