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 @@ -1236,6 +1236,11 @@ def f():
12361236 else :
12371237 1 if 1 else 1
12381238
1239+ def test_remove_empty_basic_block_with_jump_target_label (self ):
1240+ # See gh-109823
1241+ def f (x ):
1242+ while x :
1243+ 0 if 1 else 0
12391244
12401245@requires_debug_ranges ()
12411246class 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 @@ -922,6 +922,7 @@ eliminate_empty_basic_blocks(cfg_builder *g) {
922922 while (g -> g_entryblock && g -> g_entryblock -> b_iused == 0 ) {
923923 g -> g_entryblock = g -> g_entryblock -> b_next ;
924924 }
925+ int next_lbl = get_max_label (g -> g_entryblock ) + 1 ;
925926 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
926927 assert (b -> b_iused > 0 );
927928 for (int i = 0 ; i < b -> b_iused ; i ++ ) {
@@ -931,7 +932,13 @@ eliminate_empty_basic_blocks(cfg_builder *g) {
931932 while (target -> b_iused == 0 ) {
932933 target = target -> b_next ;
933934 }
934- instr -> i_target = target ;
935+ if (instr -> i_target != target ) {
936+ if (!IS_LABEL (target -> b_label )) {
937+ target -> b_label .id = next_lbl ++ ;
938+ }
939+ instr -> i_target = target ;
940+ instr -> i_oparg = target -> b_label .id ;
941+ }
935942 assert (instr -> i_target && instr -> i_target -> b_iused > 0 );
936943 }
937944 }
You can’t perform that action at this time.
0 commit comments