END_FINALLY not matching some cases

This commit is contained in:
Xinlong Hu
2025-07-07 15:49:23 -05:00
parent c7ac2dc18c
commit 5e6c46c297
@@ -530,7 +530,7 @@ class Except3_6(ControlFlowTemplate):
@classmethod
@override
def try_match(cls, cfg, node) -> ControlFlowTemplate | None:
if [x.opname for x in node.get_instructions()] == ["END_FINALLY"]:
if [x.opname for x in node.get_instructions()[:1]] == ["END_FINALLY"]:
return node
if x := ExceptExc3_6.try_match(cfg, node):
return x
@@ -543,7 +543,7 @@ class Except3_6(ControlFlowTemplate):
class Try3_6(ControlFlowTemplate):
template = T(
try_header=~N("try_body").with_cond(without_top_level_instructions("SETUP_WITH")),
try_body=N("try_footer", None, "except_body"),
try_body=N("try_footer.", None, "except_body"),
try_footer=~N("tail."),
except_body=~N("tail.").with_in_deg(1).of_subtemplate(Except3_6),
tail=N.tail(),
@@ -582,10 +582,10 @@ class ExcBody3_6(ControlFlowTemplate):
class NamedExc3_6(ExcBody3_6):
template = T(
header=~N("body", None).with_cond(starting_instructions("POP_TOP", "STORE_FAST"), with_instructions("POP_TOP", "STORE_NAME")),
header=~N("body", None).with_cond(with_instructions("POP_TOP", "STORE_FAST"), with_instructions("POP_TOP", "STORE_NAME")),
body=N("normal_cleanup.", None, "exception_cleanup"),
normal_cleanup=~N("exception_cleanup."),
exception_cleanup=~N("tail.").with_cond(with_instructions("LOAD_CONST", "STORE_FAST"), with_instructions("LOAD_CONST", "STORE_NAME")),
exception_cleanup=~N("tail.").with_cond(with_instructions("STORE_FAST", "DELETE_FAST"), with_instructions("STORE_NAME", "DELETE_NAME")),
tail=N.tail()
)
@@ -663,7 +663,7 @@ class TryElse3_6(ControlFlowTemplate):
class BareExcept3_6(Except3_6):
template = T(
except_body=~N("tail."),
except_body=~N("tail.").with_cond(starting_instructions("POP_TOP", "POP_TOP", "POP_TOP")),
tail=~N.tail(),
)