Skip to content

Prevent empty arrays from being passed to the solver #1634

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

Closed
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
18 changes: 18 additions & 0 deletions src/solvers/refinement/string_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,19 @@ exprt string_refinementt::get(const exprt &expr) const
return supert::get(ecopy);
}

/// Test whether an expression contains an empty array.
/// \param expr: expression to test
/// \return Boolean
static bool contains_empty_array(const exprt &expr)
{
auto it = std::find_if(
expr.depth_begin(),
expr.depth_end(),
[] (const exprt &e)
{ return e.id() == ID_array && e.operands().empty(); });
Copy link
Contributor

Choose a reason for hiding this comment

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

I love these iterators and lambda expressions!

return it != expr.depth_end();
}

/// Creates a solver with `axiom` as the only formula added and runs it. If it
/// is SAT, then true is returned and the given evaluation of `var` is stored
/// in `witness`. If UNSAT, then what witness is is undefined.
Expand All @@ -2138,6 +2151,11 @@ static optionalt<exprt> find_counter_example(
info.max_node_refinement=5;
info.ui=ui;
bv_refinementt solver(info);

// empty arrays cause segmentation faults in the solver
if(contains_empty_array(axiom))
return { };

solver << axiom;

if(solver()==decision_proceduret::resultt::D_SATISFIABLE)
Expand Down