@@ -170,8 +170,8 @@ taint_propagation_chainst::taint_propagation_chainst(
170
170
}
171
171
// Build predecessors of nodes of chains.
172
172
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 );
175
175
resolve_conditional_rule_applications (
176
176
program,
177
177
numbering,
@@ -242,7 +242,7 @@ taint_propagation_chainst::extend_chain_by_transition(
242
242
}
243
243
// Now we perform the the insertion of the transition to the new node and
244
244
// 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 });
246
246
const std::vector<taint_rule_idt> &to_sink_rules=
247
247
tokens_propagation_graph.get_backward_rules_from_token (
248
248
tokens_propagation_graph.get_sink_token ());
@@ -279,24 +279,45 @@ taint_propagation_chainst::erase_node(const node_idt nid)
279
279
}
280
280
281
281
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.
289
286
{
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 ());
292
290
}
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 )
295
306
{
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
+ }
299
317
}
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').
300
321
successors.at (nid)=successors.at (nodes.size ());
301
322
successors.erase (nodes.size ());
302
323
predecessors.at (nid)=predecessors.at (nodes.size ());
@@ -321,7 +342,7 @@ void taint_propagation_chainst::erase_dead_branches()
321
342
continue ;
322
343
fwd_reachable.insert (nid);
323
344
for (const auto &fns_nid : get_successors_map ().at (nid))
324
- work.push_back (fns_nid.second );
345
+ work.push_back (fns_nid.first );
325
346
}
326
347
}
327
348
// Use BFS to find all nodes backward-reachable from sinks.
@@ -448,13 +469,13 @@ std::ostream &to_dot(
448
469
for (const auto &nid : chains.get_sinks ())
449
470
ostr << " " << nid << " -> " << chains.get_nodes ().size ()+1U << " ;\n " ;
450
471
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 )
452
473
{
453
- ostr << " " << nid_edge.first << " -> " << elabel_dstnid. second ;
474
+ ostr << " " << nid_edge.first << " -> " << dstnid_elabel. first ;
454
475
ostr << " [label=\" FUNCTIONS {" ;
455
- if (!elabel_dstnid. first .empty ())
476
+ if (!dstnid_elabel. second .empty ())
456
477
ostr << " \\ l" ;
457
- for (const auto &fid : elabel_dstnid. first )
478
+ for (const auto &fid : dstnid_elabel. second )
458
479
ostr << " " << fid << " \\ l" ;
459
480
ostr << " }\\ l\" ];\n " ;
460
481
}
0 commit comments