Skip to content

Commit

Permalink
Merge branch 'BergLucas/fix/global-infinite-loops'
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanlukasczyk committed Jun 21, 2024
2 parents 1625fc4 + ad2e368 commit c6e2884
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pynguin/analyses/controlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ def _create_graph(
assert successor_node
cfg.add_edge(predecessor_node, successor_node, **attrs)

@staticmethod
def _infinite_loop_nodes(cfg: CFG) -> set[ProgramGraphNode]:
nodes: set[ProgramGraphNode] = set()
exit_nodes = cfg.exit_nodes
for node in cfg.nodes:
successors = cfg.get_successors(node)
if node in successors and successors.isdisjoint(exit_nodes):
nodes.add(node)
return nodes

@staticmethod
def _insert_dummy_entry_node(cfg: CFG) -> CFG:
dummy_entry_node = ProgramGraphNode(index=-1, is_artificial=True)
Expand All @@ -561,6 +571,8 @@ def _insert_dummy_exit_node(cfg: CFG) -> CFG:
cfg.add_node(dummy_exit_node)
for exit_node in exit_nodes:
cfg.add_edge(exit_node, dummy_exit_node)
for infinite_loop_node in CFG._infinite_loop_nodes(cfg):
cfg.add_edge(infinite_loop_node, dummy_exit_node)
return cfg

@property
Expand Down

0 comments on commit c6e2884

Please sign in to comment.