@@ -263,8 +263,9 @@ dump_instr(cfg_instr *i)
263263 if (HAS_TARGET (i -> i_opcode )) {
264264 sprintf (arg , "target: %p [%d] " , i -> i_target , i -> i_oparg );
265265 }
266- fprintf (stderr , "line: %d, %s (%d) %s%s\n" ,
267- i -> i_loc .lineno , _PyOpcode_OpName [i -> i_opcode ], i -> i_opcode , arg , jump );
266+ fprintf (stderr , "line: %d%s, %s (%d) %s%s\n" ,
267+ i -> i_loc .lineno , i -> i_loc_propagated ? "(<-)" : "" ,
268+ _PyOpcode_OpName [i -> i_opcode ], i -> i_opcode , arg , jump );
268269}
269270
270271static inline int
@@ -938,6 +939,15 @@ label_exception_targets(basicblock *entryblock) {
938939 PyMem_Free (except_stack );
939940 }
940941 }
942+
943+ for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
944+ for (int i = 0 ; i < b -> b_iused ; i ++ ) {
945+ cfg_instr * instr = & b -> b_instr [i ];
946+ if (instr -> i_opcode == POP_BLOCK ) {
947+ INSTR_SET_OP0 (instr , NOP );
948+ }
949+ }
950+ }
941951#ifdef Py_DEBUG
942952 for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
943953 assert (b -> b_exceptstack == NULL );
@@ -1006,8 +1016,9 @@ basicblock_remove_redundant_nops(basicblock *bb) {
10061016 int dest = 0 ;
10071017 int prev_lineno = -1 ;
10081018 for (int src = 0 ; src < bb -> b_iused ; src ++ ) {
1009- int lineno = bb -> b_instr [src ].i_loc .lineno ;
1010- if (bb -> b_instr [src ].i_opcode == NOP ) {
1019+ cfg_instr * src_instr = & bb -> b_instr [src ];
1020+ int lineno = src_instr -> i_loc .lineno ;
1021+ if (src_instr -> i_opcode == NOP ) {
10111022 /* Eliminate no-op if it doesn't have a line number */
10121023 if (lineno < 0 ) {
10131024 continue ;
@@ -1018,30 +1029,35 @@ basicblock_remove_redundant_nops(basicblock *bb) {
10181029 }
10191030 /* or, if the next instruction has same line number or no line number */
10201031 if (src < bb -> b_iused - 1 ) {
1021- int next_lineno = bb -> b_instr [src + 1 ].i_loc .lineno ;
1032+ cfg_instr * next_instr = & bb -> b_instr [src + 1 ];
1033+ int next_lineno = next_instr -> i_loc .lineno ;
10221034 if (next_lineno == lineno ) {
1035+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
10231036 continue ;
10241037 }
10251038 if (next_lineno < 0 ) {
1026- bb -> b_instr [src + 1 ].i_loc = bb -> b_instr [src ].i_loc ;
1039+ next_instr -> i_loc = src_instr -> i_loc ;
1040+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
10271041 continue ;
10281042 }
10291043 }
10301044 else {
1031- basicblock * next = next_nonempty_block (bb -> b_next );
10321045 /* or if last instruction in BB and next BB has same line number */
1046+ basicblock * next = next_nonempty_block (bb -> b_next );
10331047 if (next ) {
1034- location next_loc = NO_LOCATION ;
1048+ cfg_instr * next_instr = NULL ;
10351049 for (int next_i = 0 ; next_i < next -> b_iused ; next_i ++ ) {
1036- cfg_instr * instr = & next -> b_instr [next_i ];
1037- if (instr -> i_opcode == NOP && instr -> i_loc .lineno == NO_LOCATION .lineno ) {
1050+ next_instr = & next -> b_instr [next_i ];
1051+ if (next_instr -> i_opcode == NOP &&
1052+ next_instr -> i_loc .lineno == NO_LOCATION .lineno )
1053+ {
10381054 /* Skip over NOPs without location, they will be removed */
10391055 continue ;
10401056 }
1041- next_loc = instr -> i_loc ;
10421057 break ;
10431058 }
1044- if (lineno == next_loc .lineno ) {
1059+ if (next_instr && lineno == next_instr -> i_loc .lineno ) {
1060+ next_instr -> i_loc_propagated = src_instr -> i_loc_propagated ;
10451061 continue ;
10461062 }
10471063 }
@@ -2304,7 +2320,7 @@ convert_pseudo_ops(cfg_builder *g)
23042320 for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
23052321 for (int i = 0 ; i < b -> b_iused ; i ++ ) {
23062322 cfg_instr * instr = & b -> b_instr [i ];
2307- if (is_block_push (instr ) || instr -> i_opcode == POP_BLOCK ) {
2323+ if (is_block_push (instr )) {
23082324 INSTR_SET_OP0 (instr , NOP );
23092325 }
23102326 else if (instr -> i_opcode == LOAD_CLOSURE ) {
0 commit comments