gh-133371: Don't optimize LOAD_FAST instructions whose local is killed by DELETE_FAST (#133383)

In certain cases it's possible for locals loaded by `LOAD_FAST` instructions
to be on the stack when the local is killed by `DEL_FAST`. These `LOAD_FAST`
instructions should not be optimized into `LOAD_FAST_BORROW` as the strong
reference in the frame is killed while there is still a reference on the stack.
This commit is contained in:
mpage 2025-05-04 21:00:11 -07:00 committed by GitHub
parent 2bbcaedb75
commit 78adb63ee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View file

@ -2795,6 +2795,11 @@ optimize_load_fast(cfg_builder *g)
assert(opcode != EXTENDED_ARG);
switch (opcode) {
// Opcodes that load and store locals
case DELETE_FAST: {
kill_local(instr_flags, &refs, oparg);
break;
}
case LOAD_FAST: {
PUSH_REF(i, oparg);
break;