Skip to content

Commit ea285ad

Browse files
authored
gh-109923: set line number on the POP_TOP that follows a RETURN_GENERATOR (#109924)
1 parent b89ed9d commit ea285ad

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

Lib/test/test_dis.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,8 @@ async def _asyncwith(c):
524524

525525
dis_asyncwith = """\
526526
%4d RETURN_GENERATOR
527-
528-
None POP_TOP
529-
530-
%4d RESUME 0
527+
POP_TOP
528+
RESUME 0
531529
532530
%4d LOAD_FAST 0 (c)
533531
BEFORE_ASYNC_WITH
@@ -598,7 +596,6 @@ async def _asyncwith(c):
598596
ExceptionTable:
599597
12 rows
600598
""" % (_asyncwith.__code__.co_firstlineno,
601-
_asyncwith.__code__.co_firstlineno,
602599
_asyncwith.__code__.co_firstlineno + 1,
603600
_asyncwith.__code__.co_firstlineno + 2,
604601
_asyncwith.__code__.co_firstlineno + 1,
@@ -757,10 +754,8 @@ def foo(x):
757754
None COPY_FREE_VARS 1
758755
759756
%4d RETURN_GENERATOR
760-
761-
None POP_TOP
762-
763-
%4d RESUME 0
757+
POP_TOP
758+
RESUME 0
764759
LOAD_FAST 0 (.0)
765760
>> FOR_ITER 10 (to 34)
766761
STORE_FAST 1 (z)
@@ -782,7 +777,6 @@ def foo(x):
782777
__file__,
783778
_h.__code__.co_firstlineno + 3,
784779
_h.__code__.co_firstlineno + 3,
785-
_h.__code__.co_firstlineno + 3,
786780
)
787781

788782
def load_test(x, y=0):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set line number on the ``POP_TOP`` that follows a ``RETURN_GENERATOR``.

Python/flowgraph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,17 +2468,19 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
24682468
* of 0. This is because RETURN_GENERATOR pushes an element
24692469
* with _PyFrame_StackPush before switching stacks.
24702470
*/
2471+
2472+
location loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1);
24712473
cfg_instr make_gen = {
24722474
.i_opcode = RETURN_GENERATOR,
24732475
.i_oparg = 0,
2474-
.i_loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1),
2476+
.i_loc = loc,
24752477
.i_target = NULL,
24762478
};
24772479
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &make_gen));
24782480
cfg_instr pop_top = {
24792481
.i_opcode = POP_TOP,
24802482
.i_oparg = 0,
2481-
.i_loc = NO_LOCATION,
2483+
.i_loc = loc,
24822484
.i_target = NULL,
24832485
};
24842486
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 1, &pop_top));

0 commit comments

Comments
 (0)