File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1272,6 +1272,11 @@ def f():
12721272 else :
12731273 1 if 1 else 1
12741274
1275+ def test_remove_empty_basic_block_with_jump_target_label (self ):
1276+ # See gh-109823
1277+ def f (x ):
1278+ while x :
1279+ 0 if 1 else 0
12751280
12761281@requires_debug_ranges ()
12771282class TestSourcePositions (unittest .TestCase ):
Original file line number Diff line number Diff line change 1+ Fix bug where compiler does not adjust labels when removing an empty basic
2+ block which is a jump target.
Original file line number Diff line number Diff line change @@ -960,6 +960,7 @@ eliminate_empty_basic_blocks(cfg_builder *g) {
960960 while (g -> g_entryblock && g -> g_entryblock -> b_iused == 0 ) {
961961 g -> g_entryblock = g -> g_entryblock -> b_next ;
962962 }
963+ int next_lbl = get_max_label (g -> g_entryblock ) + 1 ;
963964 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
964965 assert (b -> b_iused > 0 );
965966 for (int i = 0 ; i < b -> b_iused ; i ++ ) {
@@ -969,7 +970,13 @@ eliminate_empty_basic_blocks(cfg_builder *g) {
969970 while (target -> b_iused == 0 ) {
970971 target = target -> b_next ;
971972 }
972- instr -> i_target = target ;
973+ if (instr -> i_target != target ) {
974+ if (!IS_LABEL (target -> b_label )) {
975+ target -> b_label .id = next_lbl ++ ;
976+ }
977+ instr -> i_target = target ;
978+ instr -> i_oparg = target -> b_label .id ;
979+ }
973980 assert (instr -> i_target && instr -> i_target -> b_iused > 0 );
974981 }
975982 }
You can’t perform that action at this time.
0 commit comments