]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-138679: Opcodes which consume no inputs should indicate they produced the val...
authorDino Viehland <dinoviehland@meta.com>
Mon, 8 Sep 2025 20:53:12 +0000 (13:53 -0700)
committerGitHub <noreply@github.com>
Mon, 8 Sep 2025 20:53:12 +0000 (13:53 -0700)
Opcodes which consume no inputs should indicate they produced the value, not an arbitrary local

Lib/test/test_peepholer.py
Python/flowgraph.c

index 98629df457460e852b8e99deb379d0ae3ab120cf..1caf6de4a14e3958827aa8f02615c994af5d3710 100644 (file)
@@ -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):
 
index 3a29845db9f7f85bbf4bd3fa7aa9c56950db5f9f..18594ca2f44c0f5088e6e0da4fd41504c555294d 100644 (file)
@@ -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;