Commit 833f1e66 by David Malcolm

analyzer: avoid use of fold_build2

Various places in the analyzer use fold_build2, test the result, then
discard it.  It's more efficient to use fold_binary, which avoids
building and GC-ing a redundant tree for the cases where folding fails.

gcc/analyzer/ChangeLog:
	* constraint-manager.cc (range::constrained_to_single_element):
	Replace fold_build2 with fold_binary.  Remove unnecessary newline.
	(constraint_manager::get_or_add_equiv_class): Replace fold_build2
	with fold_binary in two places, and remove out-of-date comment.
	(constraint_manager::eval_condition): Replace fold_build2 with
	fold_binary.
	* region-model.cc (constant_svalue::eval_condition): Likewise.
	(region_model::on_assignment): Likewise.
parent 8525d1f5
2020-02-03 David Malcolm <dmalcolm@redhat.com> 2020-02-03 David Malcolm <dmalcolm@redhat.com>
* constraint-manager.cc (range::constrained_to_single_element):
Replace fold_build2 with fold_binary. Remove unnecessary newline.
(constraint_manager::get_or_add_equiv_class): Replace fold_build2
with fold_binary in two places, and remove out-of-date comment.
(constraint_manager::eval_condition): Replace fold_build2 with
fold_binary.
* region-model.cc (constant_svalue::eval_condition): Likewise.
(region_model::on_assignment): Likewise.
2020-02-03 David Malcolm <dmalcolm@redhat.com>
PR analyzer/93544 PR analyzer/93544
* diagnostic-manager.cc * diagnostic-manager.cc
(diagnostic_manager::prune_for_sm_diagnostic): Bulletproof (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
......
...@@ -145,10 +145,9 @@ range::constrained_to_single_element (tree *out) ...@@ -145,10 +145,9 @@ range::constrained_to_single_element (tree *out)
m_upper_bound.ensure_closed (true); m_upper_bound.ensure_closed (true);
// Are they equal? // Are they equal?
tree comparison tree comparison = fold_binary (EQ_EXPR, boolean_type_node,
= fold_build2 (EQ_EXPR, boolean_type_node, m_lower_bound.m_constant,
m_lower_bound.m_constant, m_upper_bound.m_constant);
m_upper_bound.m_constant);
if (comparison == boolean_true_node) if (comparison == boolean_true_node)
{ {
*out = m_lower_bound.m_constant; *out = m_lower_bound.m_constant;
...@@ -932,7 +931,7 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid) ...@@ -932,7 +931,7 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid)
&& types_compatible_p (TREE_TYPE (cst), && types_compatible_p (TREE_TYPE (cst),
TREE_TYPE (ec->m_constant))) TREE_TYPE (ec->m_constant)))
{ {
tree eq = fold_build2 (EQ_EXPR, boolean_type_node, tree eq = fold_binary (EQ_EXPR, boolean_type_node,
cst, ec->m_constant); cst, ec->m_constant);
if (eq == boolean_true_node) if (eq == boolean_true_node)
{ {
...@@ -969,10 +968,8 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid) ...@@ -969,10 +968,8 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid)
Determine the direction of the inequality, and record that Determine the direction of the inequality, and record that
fact. */ fact. */
tree lt tree lt
= fold_build2 (LT_EXPR, boolean_type_node, = fold_binary (LT_EXPR, boolean_type_node,
new_ec->m_constant, other_ec.m_constant); new_ec->m_constant, other_ec.m_constant);
//gcc_assert (lt == boolean_true_node || lt == boolean_false_node);
// not true for int vs float comparisons
if (lt == boolean_true_node) if (lt == boolean_true_node)
add_constraint_internal (new_id, CONSTRAINT_LT, other_id); add_constraint_internal (new_id, CONSTRAINT_LT, other_id);
else if (lt == boolean_false_node) else if (lt == boolean_false_node)
...@@ -1018,7 +1015,7 @@ constraint_manager::eval_condition (equiv_class_id lhs_ec, ...@@ -1018,7 +1015,7 @@ constraint_manager::eval_condition (equiv_class_id lhs_ec,
if (lhs_const && rhs_const) if (lhs_const && rhs_const)
{ {
tree comparison tree comparison
= fold_build2 (op, boolean_type_node, lhs_const, rhs_const); = fold_binary (op, boolean_type_node, lhs_const, rhs_const);
if (comparison == boolean_true_node) if (comparison == boolean_true_node)
return tristate (tristate::TS_TRUE); return tristate (tristate::TS_TRUE);
if (comparison == boolean_false_node) if (comparison == boolean_false_node)
......
...@@ -670,7 +670,7 @@ constant_svalue::eval_condition (constant_svalue *lhs, ...@@ -670,7 +670,7 @@ constant_svalue::eval_condition (constant_svalue *lhs,
if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const))) if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const)))
{ {
tree comparison tree comparison
= fold_build2 (op, boolean_type_node, lhs_const, rhs_const); = fold_binary (op, boolean_type_node, lhs_const, rhs_const);
if (comparison == boolean_true_node) if (comparison == boolean_true_node)
return tristate (tristate::TS_TRUE); return tristate (tristate::TS_TRUE);
if (comparison == boolean_false_node) if (comparison == boolean_false_node)
...@@ -4088,9 +4088,9 @@ region_model::on_assignment (const gassign *assign, region_model_context *ctxt) ...@@ -4088,9 +4088,9 @@ region_model::on_assignment (const gassign *assign, region_model_context *ctxt)
if (tree rhs1_cst = maybe_get_constant (rhs1_sid)) if (tree rhs1_cst = maybe_get_constant (rhs1_sid))
if (tree rhs2_cst = maybe_get_constant (rhs2_sid)) if (tree rhs2_cst = maybe_get_constant (rhs2_sid))
{ {
tree result = fold_build2 (op, TREE_TYPE (lhs), tree result = fold_binary (op, TREE_TYPE (lhs),
rhs1_cst, rhs2_cst); rhs1_cst, rhs2_cst);
if (CONSTANT_CLASS_P (result)) if (result && CONSTANT_CLASS_P (result))
{ {
svalue_id result_sid svalue_id result_sid
= get_or_create_constant_svalue (result); = get_or_create_constant_svalue (result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment