Skip to content

SMT2 back-end: flatten with_exprt operands #8670

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
77 changes: 45 additions & 32 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4418,50 +4418,63 @@
}
else
{
auto convert_operand = [this](const exprt &op)
{
// may need to flatten array-theory arrays in there
if(op.type().id() == ID_array && use_array_theory(op))
flatten_array(op);

Check warning on line 4425 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4425

Added line #L4425 was not covered by tests
else if(op.type().id() == ID_bool)
flatten2bv(op);

Check warning on line 4427 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4427

Added line #L4427 was not covered by tests
else
convert_expr(op);
};

std::size_t struct_width=boolbv_width(struct_type);

// figure out the offset and width of the member
const boolbv_widtht::membert &m =
boolbv_width.get_member(struct_type, component_name);

out << "(let ((?withop ";
convert_expr(expr.old());
out << ")) ";

if(m.width==struct_width)
{
// the struct is the same as the member, no concat needed,
// ?withop won't be used
convert_expr(value);
}
else if(m.offset==0)
{
// the member is at the beginning
out << "(concat "
<< "((_ extract " << (struct_width-1) << " "
<< m.width << ") ?withop) ";
convert_expr(value);
out << ")"; // concat
}
else if(m.offset+m.width==struct_width)
{
// the member is at the end
out << "(concat ";
convert_expr(value);
out << " ((_ extract " << (m.offset - 1) << " 0) ?withop))";
// the struct is the same as the member, no concat needed
convert_operand(value);

Check warning on line 4441 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4441

Added line #L4441 was not covered by tests
}
else
{
// most general case, need two concat-s
out << "(concat (concat "
<< "((_ extract " << (struct_width-1) << " "
<< (m.offset+m.width) << ") ?withop) ";
convert_expr(value);
out << ") ((_ extract " << (m.offset-1) << " 0) ?withop)";
out << ")"; // concat
}
out << "(let ((?withop ";
convert_operand(expr.old());
out << ")) ";

if(m.offset == 0)
{
// the member is at the beginning
out << "(concat "
<< "((_ extract " << (struct_width - 1) << " " << m.width
<< ") ?withop) ";
convert_operand(value);
out << ")"; // concat
}
else if(m.offset + m.width == struct_width)

Check warning on line 4458 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4458

Added line #L4458 was not covered by tests
{
// the member is at the end
out << "(concat ";
convert_operand(value);
out << " ((_ extract " << (m.offset - 1) << " 0) ?withop))";

Check warning on line 4463 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4461-L4463

Added lines #L4461 - L4463 were not covered by tests
}
else
{
// most general case, need two concat-s
out << "(concat (concat "
<< "((_ extract " << (struct_width - 1) << " "
<< (m.offset + m.width) << ") ?withop) ";
convert_operand(value);
out << ") ((_ extract " << (m.offset - 1) << " 0) ?withop)";
out << ")"; // concat

Check warning on line 4473 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L4468-L4473

Added lines #L4468 - L4473 were not covered by tests
}

out << ")"; // let ?withop
out << ")"; // let ?withop
}
}
}
else if(expr_type.id() == ID_union || expr_type.id() == ID_union_tag)
Expand Down
Loading