Skip to content

Commit 7fa94ab

Browse files
committed
SMT2: implement flattening for arrays
This adds flattening for arrays into the SMT2 backend, used, for instance, when lowering unions.
1 parent 24e9d5f commit 7fa94ab

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

regression/cbmc/union/union_initialization.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE
22
union_initialization.c
33

44
^EXIT=10$

regression/cbmc/union/union_member.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-z3-smt-backend
22
union_member.c
33

44
^EXIT=10$

regression/cbmc/union/union_update.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-z3-smt-backend
22
union_update.c
33

44
^EXIT=10$

src/solvers/smt2/smt2_conv.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,31 @@ void smt2_convt::flatten2bv(const exprt &expr)
45564556
}
45574557
else if(type.id()==ID_array)
45584558
{
4559-
convert_expr(expr);
4559+
if(use_array_theory(expr))
4560+
{
4561+
// concatenate elements
4562+
const array_typet &array_type = to_array_type(type);
4563+
4564+
mp_integer size =
4565+
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));
4566+
4567+
out << "(let ((?aflop ";
4568+
convert_expr(expr);
4569+
out << ")) ";
4570+
4571+
out << "(concat";
4572+
4573+
for(mp_integer i = 0; i != size; ++i)
4574+
{
4575+
out << " (select ?aflop ";
4576+
convert_expr(from_integer(i, array_type.index_type()));
4577+
out << ')';
4578+
}
4579+
4580+
out << "))"; // concat, let
4581+
}
4582+
else
4583+
convert_expr(expr);
45604584
}
45614585
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
45624586
{
@@ -5441,7 +5465,7 @@ bool smt2_convt::use_array_theory(const exprt &expr)
54415465
}
54425466
else
54435467
{
5444-
// arrays inside structs get flattened
5468+
// arrays inside structs or unions get flattened
54455469
if(expr.id()==ID_with)
54465470
return use_array_theory(to_with_expr(expr).old());
54475471
else if(expr.id()==ID_member)

0 commit comments

Comments
 (0)