Skip to content

Commit 3559b7b

Browse files
author
Enrico Steffinlongo
committed
Add regression tests for address of array index_exprt
1 parent 8878f15 commit 3559b7b

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int example_array[10000];
4+
__CPROVER_assert(
5+
__CPROVER_OBJECT_SIZE(example_array) == 40000, "Array condition 1");
6+
__CPROVER_assert(
7+
__CPROVER_OBJECT_SIZE(example_array) == 40001, "Array condition 2");
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
array_address_of.c
3+
4+
Passing problem to incremental SMT2 solving
5+
line \d+ Array condition 1: SUCCESS
6+
line \d+ Array condition 2: FAILURE
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
11+
Test of getting the size of an array resulting in a address_of(array[0]) expression.

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,3 +1590,62 @@ TEST_CASE(
15901590
smt_bit_vector_theoryt::extract(63, 64 - object_bits)(
15911591
smt_bit_vector_theoryt::concat(object, offset))}));
15921592
}
1593+
1594+
TEST_CASE(
1595+
"lower_address_of_array_index works correctly",
1596+
"[core][smt2_incremental]")
1597+
{
1598+
auto test =
1599+
expr_to_smt_conversion_test_environmentt::make(test_archt::x86_64);
1600+
const symbol_tablet symbol_table;
1601+
const namespacet ns{symbol_table};
1602+
const typet value_type = signedbv_typet{8};
1603+
const exprt array = symbol_exprt{
1604+
"my_array", array_typet{value_type, from_integer(10, signed_size_type())}};
1605+
const exprt index = from_integer(42, unsignedbv_typet{64});
1606+
const index_exprt index_expr{array, index};
1607+
const address_of_exprt address_of_expr{index_expr};
1608+
const plus_exprt lowered{
1609+
address_of_exprt{
1610+
array, type_checked_cast<pointer_typet>(address_of_expr.type())},
1611+
index};
1612+
SECTION("Lowering address_of(array[idx])")
1613+
{
1614+
CHECK(lower_address_of_array_index(address_of_expr) == lowered);
1615+
}
1616+
SECTION("Lowering expression containing address_of(array[idx])")
1617+
{
1618+
const symbol_exprt symbol{"a_symbol", address_of_expr.type()};
1619+
const equal_exprt assignment{symbol, address_of_expr};
1620+
const equal_exprt expected{symbol, lowered};
1621+
CHECK(lower_address_of_array_index(assignment) == expected);
1622+
}
1623+
SECTION("Lowering does not lower other expressions")
1624+
{
1625+
const symbol_exprt symbol{"a_symbol", index_expr.type()};
1626+
const equal_exprt assignment{symbol, index_expr};
1627+
CHECK(lower_address_of_array_index(assignment) == assignment);
1628+
}
1629+
SECTION("Lowering is done during convert_to_smt")
1630+
{
1631+
const symbol_exprt symbol{"a_symbol", address_of_expr.type()};
1632+
const equal_exprt assignment{symbol, address_of_expr};
1633+
track_expression_objects(assignment, ns, test.object_map);
1634+
associate_pointer_sizes(
1635+
assignment,
1636+
ns,
1637+
test.pointer_sizes,
1638+
test.object_map,
1639+
test.object_size_function.make_application);
1640+
const smt_termt expected = smt_core_theoryt::equal(
1641+
smt_identifier_termt(symbol.get_identifier(), smt_bit_vector_sortt{64}),
1642+
smt_bit_vector_theoryt::add(
1643+
smt_bit_vector_theoryt::concat(
1644+
smt_bit_vector_constant_termt{2, 8},
1645+
smt_bit_vector_constant_termt{0, 56}),
1646+
smt_bit_vector_theoryt::multiply(
1647+
smt_bit_vector_constant_termt{42, 64},
1648+
smt_bit_vector_constant_termt{1, 64})));
1649+
CHECK(test.convert(assignment) == expected);
1650+
}
1651+
}

0 commit comments

Comments
 (0)