Skip to content

Commit f42edc8

Browse files
Merge pull request #7294 from thomasspriggs/tas/smt_multi_with
Add conversion of multi where/new_value with_exprt to SMT
2 parents 584c24f + 6938faa commit f42edc8

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,26 +1003,25 @@ static smt_termt convert_expr_to_smt(
10031003
}
10041004

10051005
static smt_termt convert_array_update_to_smt(
1006-
const exprt &old,
1007-
const exprt &index,
1008-
const exprt &new_value,
1006+
const with_exprt &with,
10091007
const sub_expression_mapt &converted)
10101008
{
1011-
const smt_termt &old_array_term = converted.at(old);
1012-
const smt_termt &index_term = converted.at(index);
1013-
const smt_termt &value_term = converted.at(new_value);
1014-
return smt_array_theoryt::store(old_array_term, index_term, value_term);
1009+
smt_termt array = converted.at(with.old());
1010+
for(auto it = ++with.operands().begin(); it != with.operands().end(); it += 2)
1011+
{
1012+
const smt_termt &index_term = converted.at(it[0]);
1013+
const smt_termt &value_term = converted.at(it[1]);
1014+
array = smt_array_theoryt::store(array, index_term, value_term);
1015+
}
1016+
return array;
10151017
}
10161018

10171019
static smt_termt convert_expr_to_smt(
10181020
const with_exprt &with,
10191021
const sub_expression_mapt &converted)
10201022
{
1021-
if(const auto array_type = type_try_dynamic_cast<array_typet>(with.type()))
1022-
{
1023-
return convert_array_update_to_smt(
1024-
with.old(), with.where(), with.new_value(), converted);
1025-
}
1023+
if(can_cast_type<array_typet>(with.type()))
1024+
return convert_array_update_to_smt(with, converted);
10261025
// 'with' expression is also used to update struct fields, but for now we do
10271026
// not support them, so we fail.
10281027
UNIMPLEMENTED_FEATURE(

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,15 +1239,30 @@ TEST_CASE(
12391239
array_typet{value_type, from_integer(10, signed_size_type())}};
12401240
const exprt index = from_integer(42, unsignedbv_typet{64});
12411241
const exprt value = from_integer(12, value_type);
1242-
const with_exprt with{array, index, value};
1243-
INFO("Expression being converted: " + with.pretty(2, 0));
1242+
with_exprt with{array, index, value};
12441243
const smt_termt expected = smt_array_theoryt::store(
12451244
smt_identifier_termt{
12461245
"my_array",
12471246
smt_array_sortt{smt_bit_vector_sortt{64}, smt_bit_vector_sortt{8}}},
12481247
smt_bit_vector_constant_termt{42, 64},
12491248
smt_bit_vector_constant_termt{12, 8});
1250-
CHECK(test.convert(with) == expected);
1249+
SECTION("Single where/new_value pair update")
1250+
{
1251+
INFO("Expression being converted: " + with.pretty(2, 0));
1252+
CHECK(test.convert(with) == expected);
1253+
}
1254+
SECTION("Dual where/new_value pair update")
1255+
{
1256+
exprt index2 = from_integer(24, unsignedbv_typet{64});
1257+
exprt value2 = from_integer(21, value_type);
1258+
with.add_to_operands(std::move(index2), std::move(value2));
1259+
const smt_termt expected2 = smt_array_theoryt::store(
1260+
expected,
1261+
smt_bit_vector_constant_termt{24, 64},
1262+
smt_bit_vector_constant_termt{21, 8});
1263+
INFO("Expression being converted: " + with.pretty(2, 0));
1264+
CHECK(test.convert(with) == expected2);
1265+
}
12511266
}
12521267
}
12531268

0 commit comments

Comments
 (0)