Skip to content

Make simplify_expr take copy instead of reference #4301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/analyses/ai_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool ai_domain_baset::ai_simplify_lhs(exprt &condition, const namespacet &ns)
index_exprt ie = to_index_expr(condition);
bool no_simplification = ai_simplify(ie.index(), ns);
if(!no_simplification)
condition = simplify_expr(ie, ns);
condition = simplify_expr(std::move(ie), ns);

return no_simplification;
}
Expand All @@ -57,7 +57,7 @@ bool ai_domain_baset::ai_simplify_lhs(exprt &condition, const namespacet &ns)
dereference_exprt de = to_dereference_expr(condition);
bool no_simplification = ai_simplify(de.pointer(), ns);
if(!no_simplification)
condition = simplify_expr(de, ns); // So *(&x) -> x
condition = simplify_expr(std::move(de), ns); // So *(&x) -> x

return no_simplification;
}
Expand All @@ -70,7 +70,7 @@ bool ai_domain_baset::ai_simplify_lhs(exprt &condition, const namespacet &ns)
// must also be addressable
bool no_simplification = ai_simplify_lhs(me.compound(), ns);
if(!no_simplification)
condition = simplify_expr(me, ns);
condition = simplify_expr(std::move(me), ns);

return no_simplification;
}
Expand Down
5 changes: 2 additions & 3 deletions src/analyses/custom_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ void custom_bitvector_domaint::transform(
if(to!=from->get_target())
guard = boolean_negate(guard);

exprt result=eval(guard, cba);
exprt result2=simplify_expr(result, ns);
const exprt result2 = simplify_expr(eval(guard, cba), ns);

if(result2.is_false())
make_bottom();
Expand Down Expand Up @@ -787,7 +786,7 @@ void custom_bitvector_analysist::check(

exprt tmp = eval(i_it->get_condition(), i_it);
const namespacet ns(goto_model.symbol_table);
result=simplify_expr(tmp, ns);
result = simplify_expr(std::move(tmp), ns);

description=i_it->source_location.get_comment();
}
Expand Down
4 changes: 1 addition & 3 deletions src/goto-analyzer/taint_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ bool taint_analysist::operator()(

exprt result =
custom_bitvector_analysis.eval(i_it->get_condition(), i_it);
exprt result2=simplify_expr(result, ns);

if(result2.is_true())
if(simplify_expr(std::move(result), ns).is_true())
continue;

if(first)
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/accelerate/acceleration_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,13 @@ bool acceleration_utilst::assign_array(
{
replace_expr(
loop_counter, from_integer(0, loop_counter.type()), lower_bound);
simplify_expr(lower_bound, ns);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - but I'd suggest to instead make those have an effect, e.g., by using simplify instead of simplify_expr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

lower_bound = simplify_expr(std::move(lower_bound), ns);
}
else
{
replace_expr(
loop_counter, from_integer(0, loop_counter.type()), upper_bound);
simplify_expr(upper_bound, ns);
upper_bound = simplify_expr(std::move(upper_bound), ns);
}

if(stride==0)
Expand Down
6 changes: 3 additions & 3 deletions src/solvers/lowering/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
}

if(!failed)
return simplify_expr(s, ns);
return simplify_expr(std::move(s), ns);
}
else if(src.type().id() == ID_union || src.type().id() == ID_union_tag)
{
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static exprt lower_byte_update_byte_array_vector(
result.add_to_operands(where, update_value);
}

return simplify_expr(result, ns);
return simplify_expr(std::move(result), ns);
}

/// Apply a byte update \p src to an array/vector typed operand, using the byte
Expand Down Expand Up @@ -1328,7 +1328,7 @@ static exprt lower_byte_update_array_vector_non_const(
result.add_to_operands(std::move(where), std::move(element));
}

return simplify_expr(result, ns);
return simplify_expr(std::move(result), ns);
}

/// Apply a byte update \p src to an array/vector typed operand using the byte
Expand Down
7 changes: 3 additions & 4 deletions src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2574,9 +2574,8 @@ bool simplify(exprt &expr, const namespacet &ns)
return simplify_exprt(ns).simplify(expr);
}

exprt simplify_expr(const exprt &src, const namespacet &ns)
exprt simplify_expr(exprt src, const namespacet &ns)
{
exprt tmp=src;
simplify_exprt(ns).simplify(tmp);
return tmp;
simplify_exprt(ns).simplify(src);
return src;
}
2 changes: 1 addition & 1 deletion src/util/simplify_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ bool simplify(
const namespacet &ns);

// this is the preferred interface
exprt simplify_expr(const exprt &src, const namespacet &ns);
exprt simplify_expr(exprt src, const namespacet &ns);

#endif // CPROVER_UTIL_SIMPLIFY_EXPR_H
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ static exprt actual(
const namespacet ns(symtab);

return simplify_expr(
is_digit_with_radix(chr, strict_formatting, radix_as_char, radix_ul), ns);
is_digit_with_radix(
std::move(chr), strict_formatting, radix_as_char, radix_ul),
ns);
}

/// Get the simplified return value of is_digit_with_radix called with a radix
Expand Down