Skip to content

Commit c48bc7d

Browse files
authored
Merge pull request diffblue#110 from diffblue/marek/propagation_chains_bug_fix_PR
Bug-fix in removal of dead branches in chains propagation graph
2 parents 79c83c4 + d7428d3 commit c48bc7d

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

src/taint-slicer/instrumentation_props.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ static void perform_BFS(
6262
continue;
6363
reachable.insert(nid);
6464
if(do_fwd_search)
65-
for(const auto &fns_nid : chains.get_successors_map().at(nid))
66-
work.push_back(fns_nid.second);
65+
for(const auto &nid_fns : chains.get_successors_map().at(nid))
66+
work.push_back(nid_fns.first);
6767
else
6868
for(const auto pred_nid : chains.get_predecessors_map().at(nid))
6969
work.push_back(pred_nid);
@@ -126,8 +126,8 @@ void taint_build_instrumentation_props(
126126
// Here we collect functions appearing in sets labelling edges of
127127
// chains graph.
128128
for(const auto &elem : chains.get_successors_map()) // For each node
129-
for(const auto &fns_nid : elem.second) // For each out-edge from the node
130-
for(const auto &fn : fns_nid.first) // For each label on the edge
129+
for(const auto &nid_fns : elem.second) // For each out-edge from the node
130+
for(const auto &fn : nid_fns.second) // For each label on the edge
131131
functions.insert(fn);
132132
}
133133

src/taint-slicer/propagation_chains.cpp

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ taint_propagation_chainst::taint_propagation_chainst(
170170
}
171171
// Build predecessors of nodes of chains.
172172
for(const auto &elem : successors)
173-
for(const auto &fns_nid : elem.second)
174-
predecessors[fns_nid.second].insert(elem.first);
173+
for(const auto &nid_fns : elem.second)
174+
predecessors[nid_fns.first].insert(elem.first);
175175
resolve_conditional_rule_applications(
176176
program,
177177
numbering,
@@ -242,7 +242,7 @@ taint_propagation_chainst::extend_chain_by_transition(
242242
}
243243
// Now we perform the the insertion of the transition to the new node and
244244
// we consider the case of the target node being sink.
245-
const auto res=successors[nid].insert({functions, dst_nid});
245+
const auto res=successors[nid].insert({dst_nid, functions});
246246
const std::vector<taint_rule_idt> &to_sink_rules=
247247
tokens_propagation_graph.get_backward_rules_from_token(
248248
tokens_propagation_graph.get_sink_token());
@@ -279,24 +279,45 @@ taint_propagation_chainst::erase_node(const node_idt nid)
279279
}
280280

281281
for(const auto &pred_nid : get_predecessors_map().at(nodes.size()))
282-
{
283-
auto &edges=successors.at(pred_nid);
284-
std::vector<successors_mapt::mapped_type::iterator> to_remove;
285-
for(auto it=edges.begin(); it!=edges.end(); ++it)
286-
if(it->second==nodes.size())
287-
to_remove.push_back(it);
288-
for(const auto &it : to_remove)
282+
if(pred_nid!=nodes.size()) // We have to exclude here the situation, when
283+
// the node 'nodes.size()' (i.e. the one
284+
// replacing the removed node 'nid') is its own
285+
// predecessor. We handle that situation later.
289286
{
290-
edges.insert({it->first,nid});
291-
edges.erase(it);
287+
auto &edges=successors.at(pred_nid);
288+
edges[nid].insert(edges[nodes.size()].begin(), edges[nodes.size()].end());
289+
edges.erase(nodes.size());
292290
}
293-
}
294-
for(const auto &fns_nid : get_successors_map().at(nodes.size()))
291+
for(const auto &nid_fns : get_successors_map().at(nodes.size()))
292+
if(nid_fns.first!=nodes.size()) // We have to exclude here the situation,
293+
// when the node 'nodes.size()' (i.e. the
294+
// one replacing the removed node 'nid')
295+
// is its own predecessor. We handle that
296+
// situation later.
297+
{
298+
auto &edges=predecessors.at(nid_fns.first);
299+
edges.insert(nid);
300+
edges.erase(nodes.size());
301+
}
302+
// Here we handle the situation, when the node 'nodes.size()' (i.e. the one
303+
// replacing the removed node 'nid') is its own predecessor and successor
304+
// (i.e. when this node has a loop edge).
305+
if(get_predecessors_map().at(nodes.size()).count(nodes.size())!=0UL)
295306
{
296-
auto &edges=predecessors.at(fns_nid.second);
297-
edges.insert(nid);
298-
edges.erase(nodes.size());
307+
{
308+
auto &edges=successors.at(nodes.size());
309+
edges[nid].insert(edges[nodes.size()].begin(), edges[nodes.size()].end());
310+
edges.erase(nodes.size());
311+
}
312+
{
313+
auto &edges=predecessors.at(nodes.size());
314+
edges.insert(nid);
315+
edges.erase(nodes.size());
316+
}
299317
}
318+
// Now we finally remove in- and out-edges of the node 'nid' (by replacing
319+
// them by the last node 'nodes.size()', which will become the new node
320+
// 'nid').
300321
successors.at(nid)=successors.at(nodes.size());
301322
successors.erase(nodes.size());
302323
predecessors.at(nid)=predecessors.at(nodes.size());
@@ -321,7 +342,7 @@ void taint_propagation_chainst::erase_dead_branches()
321342
continue;
322343
fwd_reachable.insert(nid);
323344
for(const auto &fns_nid : get_successors_map().at(nid))
324-
work.push_back(fns_nid.second);
345+
work.push_back(fns_nid.first);
325346
}
326347
}
327348
// Use BFS to find all nodes backward-reachable from sinks.
@@ -448,13 +469,13 @@ std::ostream &to_dot(
448469
for(const auto &nid : chains.get_sinks())
449470
ostr << " " << nid << " -> " << chains.get_nodes().size()+1U << ";\n";
450471
for(const auto &nid_edge : chains.get_successors_map())
451-
for(const auto &elabel_dstnid : nid_edge.second)
472+
for(const auto &dstnid_elabel : nid_edge.second)
452473
{
453-
ostr << " " << nid_edge.first << " -> " << elabel_dstnid.second;
474+
ostr << " " << nid_edge.first << " -> " << dstnid_elabel.first;
454475
ostr << " [label=\"FUNCTIONS {";
455-
if(!elabel_dstnid.first.empty())
476+
if(!dstnid_elabel.second.empty())
456477
ostr << "\\l";
457-
for(const auto &fid : elabel_dstnid.first)
478+
for(const auto &fid : dstnid_elabel.second)
458479
ostr << " " << fid << "\\l";
459480
ostr << "}\\l\"];\n";
460481
}

src/taint-slicer/propagation_chains.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class taint_propagation_chainst
114114

115115
typedef std::map<
116116
node_idt,
117-
std::set<std::pair<function_ids_sett, node_idt> > >
117+
std::map<node_idt, function_ids_sett> >
118118
successors_mapt;
119119
typedef std::map<node_idt, std::set<node_idt> > predecessors_mapt;
120120

0 commit comments

Comments
 (0)