]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109923: set line number on the POP_TOP that follows a RETURN_GENERATOR (#109924)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 27 Sep 2023 12:24:33 +0000 (13:24 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Sep 2023 12:24:33 +0000 (13:24 +0100)
Lib/test/test_dis.py
Misc/NEWS.d/next/Core and Builtins/2023-09-26-21-26-54.gh-issue-109923.WO3CHi.rst [new file with mode: 0644]
Python/flowgraph.c

index d104e5dd904999ede0cc75a0feeed540ad1698b5..8ab0e1ecbc4a7f7ce19008305f68b8caa7254ec9 100644 (file)
@@ -524,10 +524,8 @@ async def _asyncwith(c):
 
 dis_asyncwith = """\
 %4d        RETURN_GENERATOR
-
-None        POP_TOP
-
-%4d        RESUME                   0
+            POP_TOP
+            RESUME                   0
 
 %4d        LOAD_FAST                0 (c)
             BEFORE_ASYNC_WITH
@@ -598,7 +596,6 @@ None     >> COPY                     3
 ExceptionTable:
 12 rows
 """ % (_asyncwith.__code__.co_firstlineno,
-       _asyncwith.__code__.co_firstlineno,
        _asyncwith.__code__.co_firstlineno + 1,
        _asyncwith.__code__.co_firstlineno + 2,
        _asyncwith.__code__.co_firstlineno + 1,
@@ -757,10 +754,8 @@ Disassembly of <code object <genexpr> at 0x..., file "%s", line %d>:
 None        COPY_FREE_VARS           1
 
 %4d        RETURN_GENERATOR
-
-None        POP_TOP
-
-%4d        RESUME                   0
+            POP_TOP
+            RESUME                   0
             LOAD_FAST                0 (.0)
          >> FOR_ITER                10 (to 34)
             STORE_FAST               1 (z)
@@ -782,7 +777,6 @@ ExceptionTable:
        __file__,
        _h.__code__.co_firstlineno + 3,
        _h.__code__.co_firstlineno + 3,
-       _h.__code__.co_firstlineno + 3,
 )
 
 def load_test(x, y=0):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-26-21-26-54.gh-issue-109923.WO3CHi.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-26-21-26-54.gh-issue-109923.WO3CHi.rst
new file mode 100644 (file)
index 0000000..f218459
--- /dev/null
@@ -0,0 +1 @@
+Set line number on the ``POP_TOP`` that follows a ``RETURN_GENERATOR``.
index 9c24264cfbb45910c9695c5bc70a257e8b4084be..9fe387cc9a8e80f185fc940b9506b7da356d7c03 100644 (file)
@@ -2468,17 +2468,19 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
          * of 0. This is because RETURN_GENERATOR pushes an element
          * with _PyFrame_StackPush before switching stacks.
          */
+
+        location loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1);
         cfg_instr make_gen = {
             .i_opcode = RETURN_GENERATOR,
             .i_oparg = 0,
-            .i_loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1),
+            .i_loc = loc,
             .i_target = NULL,
         };
         RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &make_gen));
         cfg_instr pop_top = {
             .i_opcode = POP_TOP,
             .i_oparg = 0,
-            .i_loc = NO_LOCATION,
+            .i_loc = loc,
             .i_target = NULL,
         };
         RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 1, &pop_top));