Skip to content

Commit b081635

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#254 from diffblue/owen/sec-98/rename-modified-flag
SEC-98 Rename `modified` flag on EVSs
2 parents fd2df5f + 4738029 commit b081635

File tree

8 files changed

+31
-24
lines changed

8 files changed

+31
-24
lines changed

regression/LVSA/TestEVS/Test.class

11 Bytes
Binary file not shown.

regression/LVSA/TestEVS/Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void write_new_class_to_static_field() {
2525
static_node.left = new Object();
2626
}
2727

28-
public void modified(Node parameter_node) {
28+
public void is_initializer_flag(Node parameter_node) {
2929
parameter_node.left = new Object();
3030
parameter_node.right = new Object();
3131
static_object = parameter_node.left;

regression/LVSA/TestEVS/test_evs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ def test_write_new_class_to_static_field(tmpdir):
4141
output_value_expectation.check_contains_dynamic_object()
4242

4343

44-
def test_modified(tmpdir):
45-
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('modified')
44+
def test_is_initializer_flag(tmpdir):
45+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('is_initializer_flag')
4646
lvsa_expectation = lvsa_driver.run()
4747

4848
output_value_expectation_1 = lvsa_expectation.check_external_value_set('Node', '.left')
4949

5050
output_value_expectation_1.check_number_of_values(2)
5151
output_value_expectation_1.check_contains_dynamic_object(is_most_recent_allocation=True)
52-
output_value_expectation_1.check_contains_external_value_set(has_been_read=False)
52+
output_value_expectation_1.check_contains_external_value_set(is_initializer=True)
5353

5454
output_value_expectation_2 = lvsa_expectation.check_public_static('static_object')
5555

5656
output_value_expectation_2.check_number_of_values(2)
5757
output_value_expectation_2.check_contains_dynamic_object(is_most_recent_allocation=True)
58-
output_value_expectation_2.check_contains_external_value_set(has_been_read=True)
58+
output_value_expectation_2.check_contains_external_value_set(is_initializer=False)

regression/LVSA/lvsa_driver.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, evs_expr):
3535
Expr.__init__(self, evs_expr)
3636
# Expect '0' or '1', corresponding to whether the field has ever been read (and hence values from the field
3737
# could have been written to the field)
38-
self.has_been_read = evs_expr['namedSub']['modified']['id'] == '1'
38+
self.is_initializer = evs_expr['namedSub']['is_initializer']['id'] == '1'
3939
# Expect the parameter name for parameters and 'external_objects' for other things, like static fields
4040
self.label = evs_expr['sub'][0]['namedSub']['value']['id']
4141
self.is_external_object = self.label == 'external_objects'
@@ -65,14 +65,14 @@ def check_contains_dynamic_object(self, expected_number=1, is_most_recent_alloca
6565
matches = [x for x in matches if x.is_most_recent_allocation == is_most_recent_allocation]
6666
assert expected_number == len(matches)
6767

68-
def check_contains_external_value_set(self, expected_number=1, is_external_object=None, has_been_read=None):
68+
def check_contains_external_value_set(self, expected_number=1, is_external_object=None, is_initializer=None):
6969
matches = self.external_value_sets
7070
if is_external_object is not None:
7171
# Expect True or False
7272
matches = [x for x in matches if x.is_external_object == is_external_object]
73-
if has_been_read is not None:
73+
if is_initializer is not None:
7474
# Expect True or False
75-
matches = [x for x in matches if x.has_been_read == has_been_read]
75+
matches = [x for x in matches if x.is_initializer == is_initializer]
7676
assert expected_number == len(matches)
7777

7878
def get_dynamic_object_ids(self):

src/pointer-analysis/evs_pretty_printer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ std::string evs_pretty_printert::convert(const exprt &src)
2121
result << top_pretty_printer->convert(*it);
2222
}
2323
result << ")";
24-
if(src.get_bool("modified"))
25-
result << "<maybe-modified>";
24+
if(src.get_bool("is_initializer"))
25+
result << "<is-initializer>";
2626
result << " ["
2727
<< top_pretty_printer->convert(src.type())
2828
<< ']';

src/pointer-analysis/external_value_set_expr.h

+14-7
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,30 @@ class external_value_set_exprt:public exprt
8989
const typet &type,
9090
const constant_exprt &_label,
9191
const local_value_set_analysis_modet mode,
92-
bool modified):
92+
bool is_initializer):
9393
exprt(ID_external_value_set, type)
9494
{
9595
operands().resize(1);
9696
operands()[0]=_label;
9797
set("#lva_mode", std::to_string(static_cast<int>(mode)));
98-
set("modified", std::to_string(modified ? 1 : 0));
98+
set("is_initializer", std::to_string(is_initializer ? 1 : 0));
9999
}
100100

101101
local_value_set_analysis_modet analysis_mode() const
102102
{
103103
return (local_value_set_analysis_modet)get_int("#lva_mode");
104104
}
105105

106-
bool is_modified() const
106+
/// At the beginning of a function, the value set for EVS("A.b") is
107+
/// { EVS("A.b", is_initializer=true) }. Whenever EVS("A.b") gets put into a
108+
/// value set the is_initializer flag is set to false. This includes when
109+
/// it is put into the value set for EVS("A.b"), for example because of the
110+
/// line `a1.b = a2.b`. This allows us to distinguish the case that nothing
111+
/// was written to any A.b and the case that a value was written to an A.b
112+
/// from a different A.b.
113+
bool is_initializer() const
107114
{
108-
return get_bool("modified");
115+
return get_bool("is_initializer");
109116
}
110117

111118
constant_exprt &label() { return to_constant_expr(op0()); }
@@ -214,14 +221,14 @@ class external_value_set_exprt:public exprt
214221
}
215222
}
216223

217-
external_value_set_exprt as_modified() const
224+
external_value_set_exprt as_non_initializer() const
218225
{
219-
if(is_modified())
226+
if(!is_initializer())
220227
return *this;
221228
else
222229
{
223230
external_value_set_exprt copy=*this;
224-
copy.set("modified", ID_1);
231+
copy.set("is_initializer", ID_0);
225232
return copy;
226233
}
227234
}

src/pointer-analysis/local_value_set.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ void local_value_sett::assign(
329329
object_mapt values_rhs;
330330
get_value_set(rhs, values_rhs, ns, is_simplified);
331331

332-
// Special case: if an ext-val-set with modified=false is written,
333-
// set modified=true before inserting, to represent the fact that
332+
// Special case: if an ext-val-set with is_initializer=true is written,
333+
// set is_initializer=false before inserting, to represent the fact that
334334
// <some external>.x = <some external>.x might have a side-effect if
335335
// the two externals differ, and generally differentiates an
336336
// initialiser from an external set that has been read from somewhere
@@ -343,7 +343,7 @@ void local_value_sett::assign(
343343
if(objexpr.id()==ID_external_value_set)
344344
{
345345
external_value_set_exprt mod(
346-
to_external_value_set(objexpr).as_modified());
346+
to_external_value_set(objexpr).as_non_initializer());
347347
replacements.push_back({obj.first, mod});
348348
}
349349
}

src/pointer-analysis/local_value_set_analysis.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void local_value_set_analysist::initialize(const goto_programt &fun)
8484
extsym.type().subtype(),
8585
constant_exprt(extsym_name, string_typet()),
8686
mode,
87-
false);
87+
true);
8888
initial_state.insert(extsym_entry.object_map, extsym_var);
8989
}
9090
}
@@ -150,7 +150,7 @@ void local_value_set_analysist::transform_function_stub_single_external_set(
150150
auto &evse=to_external_value_set(assignment.second);
151151
// Differentiate external-set entries that only contain
152152
// their initialiser from ones that have been written:
153-
if(evse.is_modified())
153+
if(!evse.is_initializer())
154154
{
155155
lhs_written.insert({
156156
assignment.first.base_name,
@@ -163,7 +163,7 @@ void local_value_set_analysist::transform_function_stub_single_external_set(
163163
std::vector<local_value_sett::entryt*> rhs_entries;
164164
const auto &evse=to_external_value_set(assignment.second);
165165
const auto &apback=evse.access_path_back();
166-
if(evse.is_modified())
166+
if(!evse.is_initializer())
167167
{
168168
get_all_field_value_sets(
169169
id2string(apback.label()),

0 commit comments

Comments
 (0)