Skip to content

Commit 84da25e

Browse files
thomasspriggsEnrico Steffinlongo
authored andcommitted
Add with_exprt to smt conversion for array updates
1 parent 24ef4c5 commit 84da25e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,10 +991,29 @@ static smt_termt convert_expr_to_smt(
991991
"Generation of SMT formula for shift expression: " + shift.pretty());
992992
}
993993

994+
static smt_termt convert_array_update_to_smt(
995+
const exprt &old,
996+
const exprt &index,
997+
const exprt &new_value,
998+
const sub_expression_mapt &converted)
999+
{
1000+
const smt_termt &old_array_term = converted.at(old);
1001+
const smt_termt &index_term = converted.at(index);
1002+
const smt_termt &value_term = converted.at(new_value);
1003+
return smt_array_theoryt::store(old_array_term, index_term, value_term);
1004+
}
1005+
9941006
static smt_termt convert_expr_to_smt(
9951007
const with_exprt &with,
9961008
const sub_expression_mapt &converted)
9971009
{
1010+
if(const auto array_type = type_try_dynamic_cast<array_typet>(with.type()))
1011+
{
1012+
return convert_array_update_to_smt(
1013+
with.old(), with.where(), with.new_value(), converted);
1014+
}
1015+
// 'with' expression is also used to update struct fields, but for now we do
1016+
// not support them, so we fail.
9981017
UNIMPLEMENTED_FEATURE(
9991018
"Generation of SMT formula for with expression: " + with.pretty());
10001019
}

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,32 @@ TEST_CASE(
11611161
CHECK(test.convert(index_expr) == expected);
11621162
}
11631163

1164+
TEST_CASE(
1165+
"expr to smt conversion for with_exprt expressions",
1166+
"[core][smt2_incremental]")
1167+
{
1168+
auto test =
1169+
expr_to_smt_conversion_test_environmentt::make(test_archt::x86_64);
1170+
SECTION("Array types")
1171+
{
1172+
const typet value_type = signedbv_typet{8};
1173+
const exprt array = symbol_exprt{
1174+
"my_array",
1175+
array_typet{value_type, from_integer(10, signed_size_type())}};
1176+
const exprt index = from_integer(42, unsignedbv_typet{64});
1177+
const exprt value = from_integer(12, value_type);
1178+
const with_exprt with{array, index, value};
1179+
INFO("Expression being converted: " + with.pretty(2, 0));
1180+
const smt_termt expected = smt_array_theoryt::store(
1181+
smt_identifier_termt{
1182+
"my_array",
1183+
smt_array_sortt{smt_bit_vector_sortt{64}, smt_bit_vector_sortt{8}}},
1184+
smt_bit_vector_constant_termt{42, 64},
1185+
smt_bit_vector_constant_termt{12, 8});
1186+
CHECK(test.convert(with) == expected);
1187+
}
1188+
}
1189+
11641190
TEST_CASE(
11651191
"expr to smt conversion for extract bits expressions",
11661192
"[core][smt2_incremental]")

0 commit comments

Comments
 (0)