From 1561385863adb3dca0d554633090bc1d13aab415 Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Mon, 8 Sep 2025 13:53:12 -0700 Subject: [PATCH] =?utf8?q?gh-138679:=20Opcodes=20which=20consume=20no=20in?= =?utf8?q?puts=20should=20indicate=20they=20produced=20the=20val=E2=80=A6?= =?utf8?q?=20(#138678)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Opcodes which consume no inputs should indicate they produced the value, not an arbitrary local --- Lib/test/test_peepholer.py | 7 +++++++ Python/flowgraph.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 98629df45746..1caf6de4a14e 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -1116,6 +1116,13 @@ class TestMarkingVariablesAsUnKnown(BytecodeTestCase): self.assertInBytecode(f, "LOAD_FAST_BORROW") self.assertNotInBytecode(f, "LOAD_FAST_CHECK") + def test_import_from_doesnt_clobber_load_fast_borrow(self): + def f(self): + if x: pass + self.x + from shutil import ExecError + print(ExecError) + self.assertInBytecode(f, "LOAD_FAST_BORROW", "self") class DirectCfgOptimizerTests(CfgOptimizationTestCase): diff --git a/Python/flowgraph.c b/Python/flowgraph.c index 3a29845db9f7..18594ca2f44c 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -2891,7 +2891,7 @@ optimize_load_fast(cfg_builder *g) int num_pushed = _PyOpcode_num_pushed(opcode, oparg); int net_pushed = num_pushed - num_popped; assert(net_pushed >= 0); - for (int i = 0; i < net_pushed; i++) { + for (int j = 0; j < net_pushed; j++) { PUSH_REF(i, NOT_LOCAL); } break; -- 2.47.3