Skip to content

Commit e8a70da

Browse files
author
Daniel Kroening
committed
use instructiont::apply
1 parent e6267be commit e8a70da

File tree

4 files changed

+30
-53
lines changed

4 files changed

+30
-53
lines changed

src/analyses/local_safe_pointers.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Diffblue Ltd
1111

1212
#include "local_safe_pointers.h"
1313

14+
#include <util/base_type.h>
1415
#include <util/expr_iterator.h>
1516
#include <util/expr_util.h>
1617
#include <util/format_expr.h>
@@ -81,7 +82,8 @@ static optionalt<goto_null_checkt> get_null_checked_expr(const exprt &expr)
8182
/// \param goto_program: program to analyse
8283
void local_safe_pointerst::operator()(const goto_programt &goto_program)
8384
{
84-
std::set<exprt, type_comparet> checked_expressions(type_comparet{});
85+
std::set<exprt, base_type_comparet> checked_expressions(
86+
base_type_comparet{ns});
8587

8688
for(const auto &instruction : goto_program.instructions)
8789
{
@@ -96,7 +98,8 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
9698
checked_expressions = findit->second;
9799
else
98100
{
99-
checked_expressions = std::set<exprt, type_comparet>(type_comparet{});
101+
checked_expressions =
102+
std::set<exprt, base_type_comparet>(base_type_comparet{ns});
100103
}
101104
}
102105

@@ -176,11 +179,8 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
176179
/// \param out: stream to write output to
177180
/// \param goto_program: GOTO program analysed (the same one passed to
178181
/// operator())
179-
/// \param ns: namespace
180182
void local_safe_pointerst::output(
181-
std::ostream &out,
182-
const goto_programt &goto_program,
183-
const namespacet &ns)
183+
std::ostream &out, const goto_programt &goto_program)
184184
{
185185
forall_goto_program_instructions(i_it, goto_program)
186186
{
@@ -220,11 +220,8 @@ void local_safe_pointerst::output(
220220
/// \param out: stream to write output to
221221
/// \param goto_program: GOTO program analysed (the same one passed to
222222
/// operator())
223-
/// \param ns: namespace
224223
void local_safe_pointerst::output_safe_dereferences(
225-
std::ostream &out,
226-
const goto_programt &goto_program,
227-
const namespacet &ns)
224+
std::ostream &out, const goto_programt &goto_program)
228225
{
229226
forall_goto_program_instructions(i_it, goto_program)
230227
{
@@ -241,17 +238,12 @@ void local_safe_pointerst::output_safe_dereferences(
241238
out << "{";
242239
bool first = true;
243240
i_it->apply([&first, &out](const exprt &e) {
244-
for(auto subexpr_it = e.depth_begin(), subexpr_end = e.depth_end();
245-
subexpr_it != subexpr_end;
246-
++subexpr_it)
241+
if(e.id() == ID_dereference)
247242
{
248-
if(subexpr_it->id() == ID_dereference)
249-
{
250-
if(!first)
251-
out << ", ";
252-
first = true;
253-
format_rec(out, to_dereference_expr(*subexpr_it).pointer());
254-
}
243+
if(!first)
244+
out << ", ";
245+
first = true;
246+
format_rec(out, to_dereference_expr(e).pointer());
255247
}
256248
});
257249
out << "}";
@@ -272,6 +264,17 @@ bool local_safe_pointerst::is_non_null_at_program_point(
272264
auto findit = non_null_expressions.find(program_point->location_number);
273265
if(findit == non_null_expressions.end())
274266
return false;
267+
const exprt *tocheck = &expr;
268+
while(tocheck->id() == ID_typecast)
269+
tocheck = &tocheck->op0();
270+
return findit->second.count(*tocheck) != 0;
271+
}
275272

276-
return findit->second.count(skip_typecast(expr)) != 0;
273+
bool local_safe_pointerst::base_type_comparet::operator()(
274+
const exprt &e1, const exprt &e2) const
275+
{
276+
if(base_type_eq(e1, e2, ns))
277+
return false;
278+
else
279+
return e1 < e2;
277280
}

src/goto-instrument/cover_util.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,11 @@ std::set<exprt> collect_conditions(const exprt &src)
4848

4949
std::set<exprt> collect_conditions(const goto_programt::const_targett t)
5050
{
51-
switch(t->type)
52-
{
53-
case GOTO:
54-
case ASSERT:
55-
return collect_conditions(t->guard);
51+
std::set<exprt> result;
5652

57-
case ASSIGN:
58-
case FUNCTION_CALL:
59-
return collect_conditions(t->code);
53+
t->apply([&result](const exprt &e) { collect_conditions_rec(e, result); });
6054

61-
default:
62-
{
63-
}
64-
}
65-
66-
return std::set<exprt>();
55+
return result;
6756
}
6857

6958
void collect_operands(const exprt &src, std::vector<exprt> &dest)
@@ -115,20 +104,9 @@ std::set<exprt> collect_decisions(const exprt &src)
115104

116105
std::set<exprt> collect_decisions(const goto_programt::const_targett t)
117106
{
118-
switch(t->type)
119-
{
120-
case GOTO:
121-
case ASSERT:
122-
return collect_decisions(t->guard);
107+
std::set<exprt> result;
123108

124-
case ASSIGN:
125-
case FUNCTION_CALL:
126-
return collect_decisions(t->code);
109+
t->apply([&result](const exprt &e) { collect_decisions_rec(e, result); });
127110

128-
default:
129-
{
130-
}
131-
}
132-
133-
return std::set<exprt>();
111+
return result;
134112
}

src/goto-programs/compute_called_functions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ void compute_address_taken_functions(
5555
std::unordered_set<irep_idt> &address_taken)
5656
{
5757
for(const auto &i : goto_program.instructions)
58-
{
5958
i.apply([&address_taken](const exprt &expr) {
6059
compute_address_taken_functions(expr, address_taken);
6160
});
62-
}
6361
}
6462

6563
/// get all functions whose address is taken

src/goto-programs/slice_global_inits.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ void slice_global_inits(goto_modelt &goto_model)
6262
continue;
6363

6464
for(const auto &i : it->second.body.instructions)
65-
{
6665
i.apply([&symbols](const exprt &expr) {
6766
find_symbols(expr, symbols, true, false);
6867
});
69-
}
7068
}
7169

7270
// now remove unnecessary initializations

0 commit comments

Comments
 (0)