Skip to content

Commit 3e6aa3f

Browse files
committed
Handle PUSH_EXC_INFO correctly
It leaves the TOS in place.
1 parent 58db93d commit 3e6aa3f

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_peepholer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,13 @@ def test_get_yield_from_iter(self):
26812681
]
26822682
self.cfg_optimization_test(insts, insts, consts=[None])
26832683

2684+
def test_push_exc_info(self):
2685+
insts = [
2686+
("LOAD_FAST", 0, 1),
2687+
("PUSH_EXC_INFO", None, 2),
2688+
]
2689+
self.check(insts, insts)
2690+
26842691
def test_del_in_finally(self):
26852692
# This loads `obj` onto the stack, executes `del obj`, then returns the
26862693
# `obj` from the stack. See gh-133371 for more details.

Python/flowgraph.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,13 @@ optimize_load_fast(cfg_builder *g)
29482948
break;
29492949
}
29502950

2951+
case PUSH_EXC_INFO: {
2952+
ref tos = ref_stack_pop(&refs);
2953+
PUSH_REF(i, NOT_LOCAL);
2954+
PUSH_REF(tos.instr, tos.local);
2955+
break;
2956+
}
2957+
29512958
case SEND: {
29522959
load_fast_push_block(&sp, instr->i_target, refs.size);
29532960
ref_stack_pop(&refs);

0 commit comments

Comments
 (0)