Skip to content

Commit 612f33a

Browse files
author
Enrico Steffinlongo
committed
Create correct number of index id when with_exprt
As `with_exprt` can be used as a multy-ary operatior (with more than 3 arguments) we need to introduce an index smt_identifier_termt for each index used by the expression.
1 parent f42edc8 commit 612f33a

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,23 @@ void smt2_incremental_decision_proceduret::define_index_identifiers(
283283
return;
284284
if(const auto with_expr = expr_try_dynamic_cast<with_exprt>(expr_node))
285285
{
286-
const auto index_expr = with_expr->where();
287-
const auto index_term = convert_expr_to_smt(index_expr);
288-
const auto index_identifier = "index_" + std::to_string(index_sequence());
289-
const auto index_definition =
290-
smt_define_function_commandt{index_identifier, {}, index_term};
291-
expression_identifiers.emplace(index_expr, index_definition.identifier());
292-
identifier_table.emplace(index_identifier, index_definition.identifier());
293-
solver_process->send(
294-
smt_define_function_commandt{index_identifier, {}, index_term});
286+
for(auto operand_ite = ++with_expr->operands().begin();
287+
operand_ite != with_expr->operands().end();
288+
operand_ite += 2)
289+
{
290+
const auto index_expr = *operand_ite;
291+
const auto index_term = convert_expr_to_smt(index_expr);
292+
const auto index_identifier =
293+
"index_" + std::to_string(index_sequence());
294+
const auto index_definition =
295+
smt_define_function_commandt{index_identifier, {}, index_term};
296+
expression_identifiers.emplace(
297+
index_expr, index_definition.identifier());
298+
identifier_table.emplace(
299+
index_identifier, index_definition.identifier());
300+
solver_process->send(
301+
smt_define_function_commandt{index_identifier, {}, index_term});
302+
}
295303
}
296304
});
297305
}

unit/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,68 @@ TEST_CASE(
669669
REQUIRE(test.sent_commands == expected_commands);
670670
}
671671
}
672+
673+
TEST_CASE(
674+
"smt2_incremental_decision_proceduret multi-ary with_exprt introduces "
675+
"correct number of indexes.",
676+
"[core][smt2_incremental]")
677+
{
678+
auto test = decision_procedure_test_environmentt::make();
679+
const signedbv_typet index_type{32};
680+
const signedbv_typet value_type{8};
681+
const array_typet array_type{value_type, from_integer(3, index_type)};
682+
const auto original_array_symbol =
683+
make_test_symbol("original_array", array_type);
684+
const auto result_array_symbol = make_test_symbol("result_array", array_type);
685+
with_exprt with_expr{
686+
original_array_symbol.symbol_expr(),
687+
from_integer(0, index_type),
688+
from_integer(0, value_type)};
689+
with_expr.add_to_operands(
690+
from_integer(1, index_type), from_integer(1, value_type));
691+
with_expr.add_to_operands(
692+
from_integer(2, index_type), from_integer(2, value_type));
693+
const equal_exprt equal_expr{result_array_symbol.symbol_expr(), with_expr};
694+
test.sent_commands.clear();
695+
test.procedure.set_to(equal_expr, true);
696+
697+
const smt_bit_vector_sortt smt_index_sort{32};
698+
const smt_bit_vector_sortt smt_value_sort{8};
699+
const smt_array_sortt smt_array_sort{smt_index_sort, smt_value_sort};
700+
const smt_identifier_termt smt_original_array_term{
701+
"original_array", smt_array_sort};
702+
const smt_identifier_termt smt_result_array_term{
703+
"result_array", smt_array_sort};
704+
const smt_identifier_termt index_0_term{"index_0", smt_index_sort};
705+
const smt_identifier_termt index_1_term{"index_1", smt_index_sort};
706+
const smt_identifier_termt index_2_term{"index_2", smt_index_sort};
707+
const smt_termt store_term = smt_array_theoryt::store(
708+
smt_array_theoryt::store(
709+
smt_array_theoryt::store(
710+
smt_original_array_term,
711+
index_0_term,
712+
smt_bit_vector_constant_termt{0, smt_value_sort}),
713+
index_1_term,
714+
smt_bit_vector_constant_termt{1, smt_value_sort}),
715+
index_2_term,
716+
smt_bit_vector_constant_termt{2, smt_value_sort});
717+
const auto smt_assertion = smt_assert_commandt{
718+
smt_core_theoryt::equal(smt_result_array_term, store_term)};
719+
const std::vector<smt_commandt> expected_commands{
720+
smt_declare_function_commandt(smt_result_array_term, {}),
721+
smt_declare_function_commandt(smt_original_array_term, {}),
722+
smt_define_function_commandt{
723+
index_0_term.identifier(),
724+
{},
725+
smt_bit_vector_constant_termt{0, smt_index_sort}},
726+
smt_define_function_commandt{
727+
index_1_term.identifier(),
728+
{},
729+
smt_bit_vector_constant_termt{1, smt_index_sort}},
730+
smt_define_function_commandt{
731+
index_2_term.identifier(),
732+
{},
733+
smt_bit_vector_constant_termt{2, smt_index_sort}},
734+
smt_assertion};
735+
REQUIRE(test.sent_commands == expected_commands);
736+
}

0 commit comments

Comments
 (0)