Skip to content

Commit 6d407d3

Browse files
authored
Merge pull request #3842 from tautschnig/function-slicers
Slicers: do not rely on goto_programt::instructiont::function [blocks: #3126]
2 parents 81b34ab + e000621 commit 6d407d3

6 files changed

+45
-16
lines changed

src/goto-instrument/aggressive_slicer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void aggressive_slicert::get_all_functions_containing_properties()
4646
for(const auto &ins : fct.second.body.instructions)
4747
if(ins.is_assert())
4848
{
49-
if(functions_to_keep.insert(ins.function).second)
50-
note_functions_to_keep(ins.function);
49+
if(functions_to_keep.insert(fct.first).second)
50+
note_functions_to_keep(fct.first);
5151
}
5252
}
5353
}

src/goto-instrument/full_slicer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void full_slicert::add_function_calls(
3838
queuet &queue,
3939
const goto_functionst &goto_functions)
4040
{
41-
goto_functionst::function_mapt::const_iterator f_it=
42-
goto_functions.function_map.find(node.PC->function);
41+
goto_functionst::function_mapt::const_iterator f_it =
42+
goto_functions.function_map.find(node.function_id);
4343
assert(f_it!=goto_functions.function_map.end());
4444

4545
assert(!f_it->second.body.instructions.empty());
@@ -148,7 +148,7 @@ void full_slicert::add_jumps(
148148
continue;
149149
}
150150

151-
const irep_idt id=j.PC->function;
151+
const irep_idt &id = j.function_id;
152152
const cfg_post_dominatorst &pd=post_dominators.at(id);
153153

154154
cfg_post_dominatorst::cfgt::entry_mapt::const_iterator e=
@@ -182,7 +182,7 @@ void full_slicert::add_jumps(
182182

183183
if(cfg[entry->second].node_required)
184184
{
185-
const irep_idt id2=(*d_it)->function;
185+
const irep_idt &id2 = cfg[entry->second].function_id;
186186
INVARIANT(id==id2,
187187
"goto/jump expected to be within a single function");
188188

@@ -288,6 +288,11 @@ void full_slicert::operator()(
288288
{
289289
// build the CFG data structure
290290
cfg(goto_functions);
291+
forall_goto_functions(f_it, goto_functions)
292+
{
293+
forall_goto_program_instructions(i_it, f_it->second.body)
294+
cfg[cfg.entry_map[i_it]].function_id = f_it->first;
295+
}
291296

292297
// fill queue with according to slicing criterion
293298
queuet queue;
@@ -301,7 +306,7 @@ void full_slicert::operator()(
301306
e_it!=cfg.entry_map.end();
302307
e_it++)
303308
{
304-
if(criterion(e_it->first))
309+
if(criterion(cfg[e_it->second].function_id, e_it->first))
305310
add_to_queue(queue, e_it->second, e_it->first);
306311
else if(implicit(e_it->first))
307312
add_to_queue(queue, e_it->second, e_it->first);

src/goto-instrument/full_slicer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class slicing_criteriont
3333
{
3434
public:
3535
virtual ~slicing_criteriont();
36-
virtual bool operator()(goto_programt::const_targett) const = 0;
36+
virtual bool operator()(
37+
const irep_idt &function_id,
38+
goto_programt::const_targett) const = 0;
3739
};
3840

3941
void full_slicer(

src/goto-instrument/full_slicer_class.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class full_slicert
5151
}
5252

5353
bool node_required;
54+
irep_idt function_id;
5455
#ifdef DEBUG_FULL_SLICERT
5556
std::set<unsigned> required_by;
5657
#endif
@@ -109,7 +110,8 @@ class full_slicert
109110
class assert_criteriont:public slicing_criteriont
110111
{
111112
public:
112-
virtual bool operator()(goto_programt::const_targett target) const
113+
virtual bool
114+
operator()(const irep_idt &, goto_programt::const_targett target) const
113115
{
114116
return target->is_assert();
115117
}
@@ -123,9 +125,10 @@ class in_function_criteriont : public slicing_criteriont
123125
{
124126
}
125127

126-
virtual bool operator()(goto_programt::const_targett target) const
128+
virtual bool
129+
operator()(const irep_idt &function_id, goto_programt::const_targett) const
127130
{
128-
return target->function == target_function;
131+
return function_id == target_function;
129132
}
130133

131134
protected:
@@ -141,7 +144,8 @@ class properties_criteriont:public slicing_criteriont
141144
{
142145
}
143146

144-
virtual bool operator()(goto_programt::const_targett target) const
147+
virtual bool
148+
operator()(const irep_idt &, goto_programt::const_targett target) const
145149
{
146150
if(!target->is_assert())
147151
return false;

src/goto-instrument/reachability_slicer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,27 @@ reachability_slicert::get_sources(
4040
std::vector<cfgt::node_indext> sources;
4141
for(const auto &e_it : cfg.entry_map)
4242
{
43-
if(criterion(e_it.first) || is_threaded(e_it.first))
43+
if(
44+
criterion(cfg[e_it.second].function_id, e_it.first) ||
45+
is_threaded(e_it.first))
4446
sources.push_back(e_it.second);
4547
}
4648

4749
return sources;
4850
}
4951

50-
static bool is_same_target(
52+
bool reachability_slicert::is_same_target(
5153
goto_programt::const_targett it1,
52-
goto_programt::const_targett it2)
54+
goto_programt::const_targett it2) const
5355
{
5456
// Avoid comparing iterators belonging to different functions, and therefore
5557
// different std::lists.
56-
return it1->function == it2->function && it1 == it2;
58+
cfgt::entry_mapt::const_iterator it1_entry = cfg.entry_map.find(it1);
59+
cfgt::entry_mapt::const_iterator it2_entry = cfg.entry_map.find(it2);
60+
return it1_entry != cfg.entry_map.end() && it2_entry != cfg.entry_map.end() &&
61+
cfg[it1_entry->second].function_id ==
62+
cfg[it2_entry->second].function_id &&
63+
it1 == it2;
5764
}
5865

5966
/// Perform backward depth-first search of the control-flow graph of the

src/goto-instrument/reachability_slicer_class.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class reachability_slicert
2828
bool include_forward_reachability)
2929
{
3030
cfg(goto_functions);
31+
forall_goto_functions(f_it, goto_functions)
32+
{
33+
forall_goto_program_instructions(i_it, f_it->second.body)
34+
cfg[cfg.entry_map[i_it]].function_id = f_it->first;
35+
}
36+
3137
is_threadedt is_threaded(goto_functions);
3238
fixedpoint_to_assertions(is_threaded, criterion);
3339
if(include_forward_reachability)
@@ -42,10 +48,15 @@ class reachability_slicert
4248
{
4349
}
4450

51+
irep_idt function_id;
4552
bool reaches_assertion;
4653
bool reachable_from_assertion;
4754
};
4855

56+
bool is_same_target(
57+
goto_programt::const_targett it1,
58+
goto_programt::const_targett it2) const;
59+
4960
typedef cfg_baset<slicer_entryt> cfgt;
5061
cfgt cfg;
5162

0 commit comments

Comments
 (0)