Skip to content

Commit 1561385

Browse files
authored
gh-138679: Opcodes which consume no inputs should indicate they produced the val… (#138678)
Opcodes which consume no inputs should indicate they produced the value, not an arbitrary local
1 parent 6831634 commit 1561385

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/test/test_peepholer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,13 @@ def trace(frame, event, arg):
11161116
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11171117
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11181118

1119+
def test_import_from_doesnt_clobber_load_fast_borrow(self):
1120+
def f(self):
1121+
if x: pass
1122+
self.x
1123+
from shutil import ExecError
1124+
print(ExecError)
1125+
self.assertInBytecode(f, "LOAD_FAST_BORROW", "self")
11191126

11201127
class DirectCfgOptimizerTests(CfgOptimizationTestCase):
11211128

Python/flowgraph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ optimize_load_fast(cfg_builder *g)
28912891
int num_pushed = _PyOpcode_num_pushed(opcode, oparg);
28922892
int net_pushed = num_pushed - num_popped;
28932893
assert(net_pushed >= 0);
2894-
for (int i = 0; i < net_pushed; i++) {
2894+
for (int j = 0; j < net_pushed; j++) {
28952895
PUSH_REF(i, NOT_LOCAL);
28962896
}
28972897
break;

0 commit comments

Comments
 (0)