Skip to content

Commit f0de1c7

Browse files
committed
Add conversion of multi where/new_value with_exprt to SMT
This will be required due to instances of `with_exprt` of this form being produced by `src/solvers/lowering/byte_operators.cpp`.
1 parent dfcd4a8 commit f0de1c7

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,26 +1003,28 @@ 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+
auto it = ++with.operands().begin();
1011+
while(it != with.operands().end())
1012+
{
1013+
const smt_termt &index_term = converted.at(*it);
1014+
++it;
1015+
const smt_termt &value_term = converted.at(*it);
1016+
++it;
1017+
array = smt_array_theoryt::store(array, index_term, value_term);
1018+
}
1019+
return array;
10151020
}
10161021

10171022
static smt_termt convert_expr_to_smt(
10181023
const with_exprt &with,
10191024
const sub_expression_mapt &converted)
10201025
{
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-
}
1026+
if(can_cast_type<array_typet>(with.type()))
1027+
return convert_array_update_to_smt(with, converted);
10261028
// 'with' expression is also used to update struct fields, but for now we do
10271029
// not support them, so we fail.
10281030
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)