diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index b17626252fb537..683d953cea2ea9 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -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), "", "exec") @@ -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), "", "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), "", "exec") diff --git a/Python/flowgraph.c b/Python/flowgraph.c index fc676dc6feb167..ecf7c9cff8d02e 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -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;