Skip to content

Commit a96dea4

Browse files
Merge pull request #7015 from thomasspriggs/tas/fix_object_tracking_test
Fix SMT object tracking test
2 parents d69761e + de250f9 commit a96dea4

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

unit/solvers/smt2_incremental/object_tracking.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Author: Diffblue Ltd.
22

3+
#include <util/arith_tools.h>
34
#include <util/c_types.h>
45
#include <util/namespace.h>
5-
#include <util/optional.h>
66
#include <util/std_expr.h>
77
#include <util/symbol_table.h>
88

@@ -12,6 +12,84 @@
1212
#include <string>
1313
#include <utility>
1414

15+
TEST_CASE("find_object_base_expression", "[core][smt2_incremental]")
16+
{
17+
const std::size_t pointer_bits = 64;
18+
SECTION("Address of symbol")
19+
{
20+
// Constructed address of expression should be equivalent to the following
21+
// C expression - `&base`.
22+
const typet base_type = unsignedbv_typet{8};
23+
const symbol_exprt object_base{"base", base_type};
24+
const address_of_exprt address_of{
25+
object_base, pointer_typet{base_type, pointer_bits}};
26+
INFO("Address of expression is: " + address_of.pretty(2, 0));
27+
CHECK(find_object_base_expression(address_of) == object_base);
28+
}
29+
SECTION("Address of index")
30+
{
31+
// Constructed address of expression should be equivalent to the following
32+
// C expression - `&(base[index])`.
33+
const unsignedbv_typet element_type{8};
34+
const signedbv_typet index_type{pointer_bits};
35+
const array_typet base_type{element_type, from_integer(42, index_type)};
36+
const symbol_exprt object_base{"base", base_type};
37+
const symbol_exprt index{"index", index_type};
38+
const pointer_typet pointer_type{element_type, pointer_bits};
39+
const address_of_exprt address_of{
40+
index_exprt{object_base, index}, pointer_type};
41+
INFO("Address of expression is: " + address_of.pretty(2, 0));
42+
CHECK(find_object_base_expression(address_of) == object_base);
43+
}
44+
SECTION("Address of struct member")
45+
{
46+
// Constructed address of expression should be equivalent to the following
47+
// C expression - `&(base.baz)`.
48+
const struct_tag_typet base_type{"structt"};
49+
const symbol_exprt object_base{"base", base_type};
50+
const unsignedbv_typet member_type{8};
51+
const address_of_exprt address_of{
52+
member_exprt{object_base, "baz", member_type},
53+
pointer_typet{member_type, pointer_bits}};
54+
INFO("Address of expression is: " + address_of.pretty(2, 0));
55+
CHECK(find_object_base_expression(address_of) == object_base);
56+
}
57+
SECTION("Address of index of struct member")
58+
{
59+
// Constructed address of expression should be equivalent to the following
60+
// C expression - `&(base.baz[index])`.
61+
const struct_tag_typet base_type{"structt"};
62+
const symbol_exprt object_base{"base", base_type};
63+
64+
const unsignedbv_typet element_type{8};
65+
const signedbv_typet index_type{pointer_bits};
66+
const array_typet member_type{element_type, from_integer(42, index_type)};
67+
const symbol_exprt index{"index", index_type};
68+
69+
const address_of_exprt address_of{
70+
index_exprt{member_exprt{object_base, "baz", member_type}, index},
71+
pointer_typet{element_type, pointer_bits}};
72+
INFO("Address of expression is: " + address_of.pretty(2, 0));
73+
CHECK(find_object_base_expression(address_of) == object_base);
74+
}
75+
SECTION("Address of struct member at index")
76+
{
77+
// Constructed address of expression should be equivalent to the following
78+
// C expression - `&(base[index].qux)`.
79+
const struct_tag_typet element_type{"struct_elementt"};
80+
const signedbv_typet index_type{pointer_bits};
81+
const array_typet base_type{element_type, from_integer(42, index_type)};
82+
const symbol_exprt object_base{"base", base_type};
83+
const symbol_exprt index{"index", index_type};
84+
const unsignedbv_typet member_type{8};
85+
const address_of_exprt address_of{
86+
member_exprt{index_exprt{object_base, index}, "qux", member_type},
87+
pointer_typet{member_type, pointer_bits}};
88+
INFO("Address of expression is: " + address_of.pretty(2, 0));
89+
CHECK(find_object_base_expression(address_of) == object_base);
90+
}
91+
}
92+
1593
TEST_CASE("Tracking object base expressions", "[core][smt2_incremental]")
1694
{
1795
const typet base_type = pointer_typet{signedbv_typet{16}, 18};

0 commit comments

Comments
 (0)