Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 33 additions & 8 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ def test_compile_redundant_jumps_and_nops_after_moving_cold_blocks(self):
# make all instruction locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

Expand All @@ -639,10 +639,35 @@ def test_compile_redundant_jump_after_convert_pseudo_ops(self):
# make all instruction locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

def test_compile_fallthrough_to_unreachable_block_after_convert_pseudo_ops(self):
# See gh-162952
code=textwrap.dedent("""
while name_2:
break
else:
try:
pass
finally:
pass
lambda: 0
""")

tree = ast.parse(code)

# make all instruction locations the same to create redundancies
for node in ast.walk(tree):
if hasattr(node,"lineno"):
del node.lineno
del node.end_lineno
del node.col_offset
del node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

Expand Down
6 changes: 5 additions & 1 deletion Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,11 @@ static void
load_fast_push_block(basicblock ***sp, basicblock *target,
Py_ssize_t start_depth)
{
assert(target->b_startdepth >= 0 && target->b_startdepth == start_depth);
if (target->b_startdepth < 0) {
assert(target->b_iused == 0);
target->b_startdepth = (int)start_depth;
}
assert(target->b_startdepth == start_depth);
if (!target->b_visited) {
target->b_visited = 1;
*(*sp)++ = target;
Expand Down
Loading