Skip to content

SMT2: implement flattening for arrays #7290

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 1 commit into from
Nov 3, 2022
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
2 changes: 1 addition & 1 deletion regression/cbmc/union/union_initialization.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE
union_initialization.c

^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/union/union_member.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE broken-z3-smt-backend
union_member.c

^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/union/union_update.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE broken-smt-backend
CORE broken-z3-smt-backend
union_update.c

^EXIT=10$
Expand Down
28 changes: 26 additions & 2 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4556,7 +4556,31 @@ void smt2_convt::flatten2bv(const exprt &expr)
}
else if(type.id()==ID_array)
{
convert_expr(expr);
if(use_array_theory(expr))
{
// concatenate elements
const array_typet &array_type = to_array_type(type);

mp_integer size =
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));

out << "(let ((?aflop ";
convert_expr(expr);
out << ")) ";

out << "(concat";

for(mp_integer i = 0; i != size; ++i)
{
out << " (select ?aflop ";
convert_expr(from_integer(i, array_type.index_type()));
out << ')';
}

out << "))"; // concat, let
}
else
convert_expr(expr);
}
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
{
Expand Down Expand Up @@ -5441,7 +5465,7 @@ bool smt2_convt::use_array_theory(const exprt &expr)
}
else
{
// arrays inside structs get flattened
// arrays inside structs or unions get flattened
if(expr.id()==ID_with)
return use_array_theory(to_with_expr(expr).old());
else if(expr.id()==ID_member)
Expand Down