Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loops in global scope #65

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/pynguin/analyses/controlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,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 @@ -567,6 +577,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
Loading