Skip to content

Commit d7c5070

Browse files
authored
Merge pull request diffblue#492 from diffblue/smowton/cleanup/remove-nondet-handlers
Remove nondet expression handlers
2 parents 17fa8a7 + b87b7ac commit d7c5070

8 files changed

+3
-202
lines changed

src/taint-analysis/taint_program.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,95 +12,13 @@
1212
#include <analyses/call_graph_helpers.h>
1313
#include <unordered_set>
1414

15-
/// Remove assignment of non-dets to values if they can't be reached
16-
/// Mark instances of function call followed by assignment of non-det to
17-
/// function's return value
18-
static void build_NONDET_retvals_replacements(
19-
const goto_modelt &model,
20-
const namespacet &ns,
21-
replacements_of_NONDET_retvalst &replacements)
22-
{
23-
for(const auto &elem : model.goto_functions.function_map)
24-
{
25-
const goto_programt::instructionst &instructions =
26-
elem.second.body.instructions;
27-
for(auto instr_it = instructions.begin(); instr_it != instructions.end();
28-
++instr_it)
29-
{
30-
auto next_instr_it = std::next(instr_it);
31-
if(
32-
next_instr_it != instructions.end() &&
33-
instr_it->type == FUNCTION_CALL && next_instr_it->type == ASSIGN)
34-
{
35-
const code_assignt &asgn = to_code_assign(next_instr_it->code);
36-
if(asgn.rhs().id() != ID_side_effect)
37-
continue;
38-
const side_effect_exprt see = to_side_effect_expr(asgn.rhs());
39-
if(see.get_statement() != ID_nondet)
40-
continue;
41-
42-
const code_function_callt &fn_call =
43-
to_code_function_call(instr_it->code);
44-
if(fn_call.function().id() != ID_symbol)
45-
continue;
46-
const irep_idt &callee_ident =
47-
to_symbol_expr(fn_call.function()).get_identifier();
48-
49-
std::string callee_return_value_symbol =
50-
id2string(callee_ident) + RETURN_VALUE_SUFFIX;
51-
if(!ns.get_symbol_table().has_symbol(callee_return_value_symbol))
52-
continue;
53-
54-
replacements.insert(
55-
{
56-
next_instr_it,
57-
ns.lookup(callee_return_value_symbol).symbol_expr()
58-
});
59-
}
60-
else if(instr_it->type == ASSIGN)
61-
{
62-
const code_assignt &assign = to_code_assign(instr_it->code);
63-
if(assign.rhs().id() != ID_side_effect)
64-
continue;
65-
const side_effect_exprt side_effect = to_side_effect_expr(assign.rhs());
66-
if(side_effect.get_statement() != ID_nondet)
67-
continue;
68-
if(side_effect.type().id() != ID_pointer)
69-
continue;
70-
// Create a new static variable to put on the rhs of this
71-
// assignment. When the instruction is dead then this is sound.
72-
// Otherwise this is not sound, but it is preferable to having a
73-
// pointer that could point to anything. A better solution would be
74-
// to use the convert_nondet pass or similar.
75-
static unsigned long counter = 0UL;
76-
std::stringstream sstr;
77-
sstr << "@__CPROVER_NONDET_dead_replace_" << ++counter;
78-
symbolt symbol;
79-
symbol.type =
80-
side_effect.type().id() == ID_pointer
81-
? to_pointer_type(side_effect.type()).subtype()
82-
: side_effect.type();
83-
symbol.name = sstr.str();
84-
symbol.base_name = symbol.name;
85-
symbol.mode = ID_java;
86-
symbol.pretty_name = symbol.name;
87-
symbol.is_static_lifetime = true;
88-
const_cast<symbol_tablet &>(model.symbol_table).insert(symbol);
89-
replacements.insert({ instr_it, symbol.symbol_expr() });
90-
}
91-
}
92-
}
93-
}
94-
9515
taint_programt::taint_programt(
9616
const goto_modelt &model,
9717
taint_statisticst &statistics)
9818
: model(model), ns(model.symbol_table)
9919
{
10020
statistics.begin_goto_program_building();
10121

102-
build_NONDET_retvals_replacements(model, ns, NONDET_retvals_replacements);
103-
10422
class_hierarchy(model.symbol_table);
10523

10624
call_graph = call_grapht(model.goto_functions);

src/taint-analysis/taint_program.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ class taint_programt
7979
return inverted_topological_order;
8080
}
8181

82-
const replacements_of_NONDET_retvalst& get_NONDET_retvals_replacements()
83-
const noexcept
84-
{
85-
return NONDET_retvals_replacements;
86-
}
87-
8882
private:
8983
taint_programt() = delete;
9084
taint_programt(const taint_programt &) = delete;
@@ -97,7 +91,6 @@ class taint_programt
9791
call_grapht inv_call_graph;
9892
call_grapht::directed_grapht directed_call_graph;
9993
std::vector<irep_idt> inverted_topological_order;
100-
replacements_of_NONDET_retvalst NONDET_retvals_replacements;
10194
};
10295

10396

src/taint-analysis/taint_statistics.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ static bool is_instruction_GOTO(goto_programt::instructiont const& I)
7777
return I.type == GOTO && I.guard.id() == ID_constant;
7878
}
7979

80-
static bool is_instruction_call_NONDET(goto_programt::instructiont const& I)
81-
{
82-
if (I.type == ASSIGN)
83-
{
84-
code_assignt const& asgn = to_code_assign(I.code);
85-
if (asgn.rhs().id() == ID_side_effect)
86-
{
87-
side_effect_exprt const see = to_side_effect_expr(asgn.rhs());
88-
if(see.get_statement() == ID_nondet)
89-
return true;
90-
}
91-
}
92-
return false;
93-
}
94-
9580
static bool is_instruction_StringBuilder_call(
9681
goto_programt::instructiont const& I,
9782
const namespacet &ns)
@@ -153,7 +138,6 @@ taint_function_statisticst::taint_function_statisticst(
153138
num_temporaries(0UL),
154139
num_assignments_to_temporaries(0UL),
155140
num_dead_statements(0UL),
156-
num_NONDET_calls(0UL),
157141
num_SKIPs(0UL),
158142
num_GOTOs(0UL),
159143
num_string_builder_lines(0UL),
@@ -424,11 +408,6 @@ void taint_statisticst::end_goto_program_building(
424408
fn_stats.on_dead_statement();
425409
is_auxiliaty = true;
426410
}
427-
if(is_instruction_call_NONDET(I))
428-
{
429-
fn_stats.on_NONDET_call();
430-
is_auxiliaty = true;
431-
}
432411
if(is_instruction_SKIP(I))
433412
{
434413
fn_stats.on_SKIP();

src/taint-analysis/taint_statistics.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class taint_function_statisticst
4141
void on_temporary() { ++num_temporaries; }
4242
void on_assignment_to_temporary() { ++num_assignments_to_temporaries; }
4343
void on_dead_statement() { ++num_dead_statements; }
44-
void on_NONDET_call() { ++num_NONDET_calls; }
4544
void on_SKIP() { ++num_SKIPs; }
4645
void on_GOTO() { ++num_GOTOs; }
4746
void on_string_builder_line() { ++num_string_builder_lines; }
@@ -84,8 +83,6 @@ class taint_function_statisticst
8483
{ return num_assignments_to_temporaries; }
8584
std::size_t get_num_dead_statements() const noexcept
8685
{ return num_dead_statements; }
87-
std::size_t get_num_NONDET_calls() const noexcept
88-
{ return num_NONDET_calls; }
8986
std::size_t get_num_SKIPs() const noexcept
9087
{ return num_SKIPs; }
9188
std::size_t get_num_GOTOs() const noexcept
@@ -157,7 +154,6 @@ class taint_function_statisticst
157154
std::size_t num_temporaries;
158155
std::size_t num_assignments_to_temporaries;
159156
std::size_t num_dead_statements;
160-
std::size_t num_NONDET_calls;
161157
std::size_t num_SKIPs;
162158
std::size_t num_GOTOs;
163159
std::size_t num_string_builder_lines;

src/taint-analysis/taint_statistics_dump_html.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ static void taint_global_program_stats_table(
202202
std::size_t num_temporaries = 0UL;
203203
std::size_t num_assgns_to_temporaries = 0UL;
204204
std::size_t num_dead_statements = 0UL;
205-
std::size_t num_NONDET_calls = 0UL;
206205
std::size_t num_SKIPs = 0UL;
207206
std::size_t num_GOTOs = 0UL;
208207
std::size_t num_string_builders = 0UL;
@@ -219,7 +218,6 @@ static void taint_global_program_stats_table(
219218
num_temporaries += fS.get_num_temporaries();
220219
num_assgns_to_temporaries += fS.get_num_assignments_to_temporaries();
221220
num_dead_statements += fS.get_num_dead_statements();
222-
num_NONDET_calls += fS.get_num_NONDET_calls();
223221
num_SKIPs += fS.get_num_SKIPs();
224222
num_GOTOs += fS.get_num_GOTOs();
225223
num_string_builders += fS.get_num_string_builder_lines();
@@ -266,12 +264,6 @@ static void taint_global_program_stats_table(
266264
" </tr>\n"
267265
;
268266

269-
ostr << " <tr>\n"
270-
" <td>Number of locations performing calls to NONDET()</td>\n"
271-
" <td align=\"right\">" << num_NONDET_calls << "</td>\n"
272-
" </tr>\n"
273-
;
274-
275267
ostr << " <tr>\n"
276268
" <td>Number of SKIP statement locations</td>\n"
277269
" <td align=\"right\">" << num_SKIPs << "</td>\n"
@@ -365,12 +357,6 @@ static void taint_function_stats_table(
365357
" </tr>\n"
366358
;
367359

368-
ostr << " <tr>\n"
369-
" <td>Number of calls to NONDET() function</td>\n"
370-
" <td align=\"right\">" << fS.get_num_NONDET_calls() << "</td>\n"
371-
" </tr>\n"
372-
;
373-
374360
ostr << " <tr>\n"
375361
" <td>Number of SKIP statements</td>\n"
376362
" <td align=\"right\">" << fS.get_num_SKIPs() << "</td>\n"

src/taint-analysis/taint_statistics_dump_json.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ static void taint_dump_files_table(
9797
);
9898
fn_table["num-DEAD-statements"] =
9999
json_numbert(msgstream() << fS.get_num_dead_statements());
100-
fn_table["num-NONDET-calls"] =
101-
json_numbert(msgstream() << fS.get_num_NONDET_calls());
102100
fn_table["num-SKIP-statements"] =
103101
json_numbert(msgstream() << fS.get_num_SKIPs());
104102
fn_table["num-GOTO-unconditional-statements"] =
@@ -191,4 +189,4 @@ void taint_dump_statistics_in_JSON(
191189
boost::filesystem::create_directory(out_file_pathname.parent_path());
192190
std::ofstream ostr(out_file_pathname.native());
193191
taint_dump_statistics_in_JSON(stats, ostr);
194-
}
192+
}

src/taint-analysis/taint_summary.cpp

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,6 @@ static void collect_lvsa_access_paths(
179179
{
180180
TMPROF_BLOCK();
181181

182-
if(query.id() == ID_side_effect)
183-
{
184-
const side_effect_exprt &see = to_side_effect_expr(query);
185-
if(see.get_statement()==ID_nondet)
186-
{
187-
// TODO(marek-trtik): Add computation of a proper points-to set for NONDET
188-
// in a side-effect expression
189-
}
190-
}
191-
192182
if(
193183
query.id() == ID_symbol || query.id() == ID_index ||
194184
query.id() == ID_member || query.id() == ID_dereference)
@@ -984,64 +974,7 @@ numbered_lvalue_to_taint_mapt taint_algorithm_computing_summary_of_functiont::
984974

985975
transition_properties[Iit].push_back(
986976
{taint_transition_property_typet::ASSIGNMENT, taint_rule_idt{}, ""});
987-
const code_assignt &asgn=to_code_assign(I.code);
988-
if(asgn.rhs().id()==ID_side_effect)
989-
{
990-
const side_effect_exprt see=to_side_effect_expr(asgn.rhs());
991-
if(see.get_statement()==ID_nondet)
992-
{
993-
const auto replace_it=
994-
program->get_NONDET_retvals_replacements().find(Iit);
995-
if(replace_it!=program->get_NONDET_retvals_replacements().cend())
996-
{
997-
taint_sett taint =
998-
compute_taint_of_aliased_numbers_of_lvalue(
999-
replace_it->second, Iit, lvsa, input, a);
1000-
1001-
lvalue_numbers_sett numbers_of_aliases;
1002-
collect_lvsa_access_paths_extended(
1003-
replace_it->second, Iit, lvsa, numbers_of_aliases);
1004-
assert(!numbers_of_aliases.empty());
1005-
std::stringstream sstr;
1006-
sstr << "However, instead of applying NONDET as the right-hand-side"
1007-
" expression of the assignment, join of values of these "
1008-
"expressions was taken:";
1009-
bool first = true;
1010-
for(const auto num : numbers_of_aliases)
1011-
{
1012-
assert(num < numbering->size());
1013-
if(!first)
1014-
sstr << ", ";
1015-
sstr << from_expr(program->get_namespace(), "", numbering->at(num));
1016-
first = false;
1017-
}
1018-
sstr << ".";
1019-
transition_properties[Iit].push_back(
1020-
{taint_transition_property_typet::ASSIGNMENT,
1021-
taint_rule_idt{},
1022-
sstr.str()});
1023-
1024-
lvalue_numbers_sett lhs;
1025-
collect_lvsa_access_paths_extended(asgn.lhs(), Iit, lvsa, lhs);
1026-
for(const auto& path : lhs)
1027-
{
1028-
if(lhs.size() > 1UL)
1029-
maybe_assign(result, path, taint);
1030-
else
1031-
assign(result, path, taint);
1032-
}
1033-
return result;
1034-
}
1035-
else
1036-
{
1037-
// If this is not listed in get_NONDET_retvals, then it must be
1038-
// unrelated to a stub function call and does not need this special
1039-
// treatment.
1040-
break;
1041-
}
1042-
}
1043-
}
1044-
handle_assignment(asgn, a, input, result, Iit, lvsa);
977+
handle_assignment(to_code_assign(I.code), a, input, result, Iit, lvsa);
1045978
}
1046979
break;
1047980
case FUNCTION_CALL:

src/taint-slicer/instrumenter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ exprt make_or_update_initialiser(
109109
const std::set<taint_instrumentert::automaton_variable_idt> &
110110
names_of_shadow_variables)
111111
{
112-
if(new_type.id()!=ID_struct ||
113-
(initialiser.id() == ID_side_effect &&
114-
to_side_effect_expr(initialiser).get_statement() == ID_nondet))
112+
if(new_type.id() != ID_struct)
115113
{
116114
// Rewrite type regardless, for example to turn (array*)null into
117115
// (wrapped_array*)null

0 commit comments

Comments
 (0)