Skip to content

Commit e26f4cd

Browse files
Check pointer evaluation in the member case
Field sensitivity the value set to keep track of pointers in individal fields, making it possible to evaluate equalities such as the one in the example. This is a case which would not work if try_evaluate_pointer_comparisons was using get_l1_object_identifier instead of getting the identifier of the whole l1 expression (not the underlying object). fixup! Check pointer evaluation in the array case
1 parent 2c34886 commit e26f4cd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

unit/goto-symex/try_evaluate_pointer_comparisons.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Romain Brenguier, [email protected]
1010
#include <testing-utils/use_catch.h>
1111

1212
#include <goto-symex/goto_symex.h>
13+
#include <util/arith_tools.h>
1314
#include <util/c_types.h>
1415

1516
static void add_to_symbol_table(
@@ -127,4 +128,55 @@ SCENARIO(
127128
}
128129
}
129130
}
131+
132+
GIVEN("A struct whose first element can only point to `&value1`")
133+
{
134+
// member is `struct_symbol.pointer_field`
135+
const member_exprt member = [&]() {
136+
std::vector<struct_typet::componentt> components;
137+
components.emplace_back("pointer_field", ptr_type);
138+
const struct_typet struct_type{components};
139+
const symbol_exprt struct_symbol{"struct_symbol", struct_type};
140+
add_to_symbol_table(symbol_table, struct_symbol);
141+
return member_exprt{struct_symbol, components.back()};
142+
}();
143+
144+
value_sett value_set;
145+
const renamedt<exprt, L1> member_l1 = state.rename<L1>(member, ns);
146+
const renamedt<exprt, L1> address1_l1 = state.rename<L1>(address1, ns);
147+
148+
// struct_symbol..pointer_field <- &value1
149+
{
150+
field_sensitivityt field_sensitivity;
151+
const exprt index_fs =
152+
field_sensitivity.apply(ns, state, member_l1.get(), true);
153+
value_set.assign(index_fs, address1_l1.get(), ns, false, false);
154+
}
155+
156+
WHEN("Evaluating struct_symbol.pointer_field == &value1")
157+
{
158+
const equal_exprt comparison{member, address1};
159+
const renamedt<exprt, L2> renamed_comparison =
160+
state.rename(comparison, ns);
161+
auto result = try_evaluate_pointer_comparisons(
162+
renamed_comparison, value_set, ID_java, ns);
163+
THEN("Evaluation succeeds")
164+
{
165+
REQUIRE(result.get() == true_exprt{});
166+
}
167+
}
168+
169+
WHEN("Evaluating struct_symbol.pointer_field == &value2")
170+
{
171+
const equal_exprt comparison{member, address2};
172+
const renamedt<exprt, L2> renamed_comparison =
173+
state.rename(comparison, ns);
174+
auto result = try_evaluate_pointer_comparisons(
175+
renamed_comparison, value_set, ID_java, ns);
176+
THEN("Evaluation succeeds")
177+
{
178+
REQUIRE(result.get() == false_exprt{});
179+
}
180+
}
181+
}
130182
}

0 commit comments

Comments
 (0)