diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-11-02 10:18:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 10:18:43 +0000 |
commit | 52cc4af6ae9002f11605f91b672746c127494efd (patch) | |
tree | 1bb4c679b3e179fdb9ccbacff4316c98fd594e79 /Python/flowgraph.c | |
parent | 970e719a7a829bddc647bbaa668dd8603abdddef (diff) | |
download | cpython-52cc4af6ae9002f11605f91b672746c127494efd.tar.gz cpython-52cc4af6ae9002f11605f91b672746c127494efd.zip |
gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 (#111459)
Diffstat (limited to 'Python/flowgraph.c')
-rw-r--r-- | Python/flowgraph.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Python/flowgraph.c b/Python/flowgraph.c index e89ad39b357..87401e14f97 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -840,6 +840,7 @@ label_exception_targets(basicblock *entryblock) { assert(except_stack != NULL); b->b_exceptstack = NULL; handler = except_stack_top(except_stack); + int last_yield_except_depth = -1; for (int i = 0; i < b->b_iused; i++) { cfg_instr *instr = &b->b_instr[i]; if (is_block_push(instr)) { @@ -878,10 +879,21 @@ label_exception_targets(basicblock *entryblock) { todo++; } } - else { - if (instr->i_opcode == YIELD_VALUE) { - instr->i_oparg = except_stack->depth; + else if (instr->i_opcode == YIELD_VALUE) { + instr->i_except = handler; + last_yield_except_depth = except_stack->depth; + } + else if (instr->i_opcode == RESUME) { + instr->i_except = handler; + if (instr->i_oparg != RESUME_AT_FUNC_START) { + assert(last_yield_except_depth >= 0); + if (last_yield_except_depth == 1) { + instr->i_oparg |= RESUME_OPARG_DEPTH1_MASK; + } + last_yield_except_depth = -1; } + } + else { instr->i_except = handler; } } |