Skip to content

Commit b837440

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#298 from diffblue/owen-jones-diffblue/bugfix/initializer-evs-spreads-to-dynamic-object
Fix bug that initializer evs can spread to dynamic objects
2 parents ec1d691 + 8fdad56 commit b837440

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed
358 Bytes
Binary file not shown.

regression/LVSA/TestPreciseAccessPaths/Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ public void get_list_node(ListNode list_node, int index) {
5959
}
6060
output = list_node.data;
6161
}
62+
63+
public void simple_function_should_export_imprecise_access_paths(A param_a) {
64+
param_a.left_object = new Object();
65+
}
66+
67+
public void check_using_imprecise_access_paths() {
68+
A dynamic_object_1 = new A();
69+
A dynamic_object_2 = new A();
70+
simple_function_should_export_imprecise_access_paths(dynamic_object_2);
71+
output = dynamic_object_1.left_object;
72+
}
6273
}

regression/LVSA/TestPreciseAccessPaths/test_precise_access_paths.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from regression.LVSA.lvsa_driver import LvsaDriver
24

35

@@ -82,3 +84,15 @@ def test_get_list_node(tmpdir):
8284

8385
value_set_expectation.check_number_of_values(1)
8486
value_set_expectation.check_contains_external_value_set()
87+
88+
89+
def test_check_using_imprecise_access_paths(tmpdir):
90+
# This test should change when precise access paths have been implemented
91+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('check_using_imprecise_access_paths')
92+
lvsa_expectation = lvsa_driver.run()
93+
94+
value_set_expectation = lvsa_expectation.get_value_set_for_public_static('output')
95+
96+
value_set_expectation.check_number_of_values(2)
97+
value_set_expectation.check_contains_null_object()
98+
value_set_expectation.check_contains_dynamic_object()

src/pointer-analysis/local_value_set_analysis.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,9 @@ void local_value_set_analysist::transform_function_stub(
173173
std::map<exprt, local_value_sett::object_mapt> pre_call_rhs_value_sets;
174174
const std::string per_field_evs_prefix="external_objects";
175175

176-
std::set<std::pair<std::string, std::string> > lhs_written;
177-
178176
for(const auto &assignment : assignments)
179177
{
180178
++nstub_assignments;
181-
const auto &lhs_fieldname=assignment.first;
182179
const auto &rhs_expr=assignment.second;
183180
if(pre_call_rhs_value_sets.count(rhs_expr))
184181
continue;
@@ -191,11 +188,6 @@ void local_value_set_analysist::transform_function_stub(
191188
const std::string &evse_label=
192189
id2string(to_constant_expr(evse.label()).get_value());
193190

194-
// Differentiate external-set entries that only contain
195-
// their initialiser from ones that have been written:
196-
if(!evse.is_initializer())
197-
lhs_written.insert({lhs_fieldname.base_name, lhs_fieldname.field_name});
198-
199191
if(has_prefix(evse_label, per_field_evs_prefix))
200192
{
201193
// This external value set denotes either all pointers stored in a
@@ -275,7 +267,6 @@ void local_value_set_analysist::transform_function_stub(
275267
// Ordinary value set member (not an external value set);
276268
// just add to the RHS map.
277269
valuesets.insert(rhs_map, rhs_expr);
278-
lhs_written.insert({lhs_fieldname.base_name, lhs_fieldname.field_name});
279270
}
280271
}
281272

@@ -295,12 +286,21 @@ void local_value_set_analysist::transform_function_stub(
295286
const auto find_pair=std::make_pair(
296287
lhs_fieldname.base_name,
297288
lhs_fieldname.field_name);
298-
if(lhs_written.count(find_pair))
289+
290+
const bool rhs_is_initializer_per_field_evs =
291+
assignment.second.id() == ID_external_value_set &&
292+
to_external_value_set(assignment.second)
293+
.get_external_value_set_type() ==
294+
external_value_set_typet::PER_FIELD &&
295+
to_external_value_set(assignment.second).is_initializer();
296+
if(!rhs_is_initializer_per_field_evs)
297+
{
299298
get_all_field_value_sets(
300299
lhs_fieldname.field_name,
301300
lhs_fieldname.declared_on_type,
302301
valuesets,
303302
lhs_entries);
303+
}
304304

305305
// Also write to the external value set itself, representing writes
306306
// whose effects are external to this context too:

0 commit comments

Comments
 (0)