File tree 3 files changed +15
-1
lines changed
Misc/NEWS.d/next/Core and Builtins
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1272,6 +1272,11 @@ def f():
1272
1272
else :
1273
1273
1 if 1 else 1
1274
1274
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
1275
1280
1276
1281
@requires_debug_ranges ()
1277
1282
class 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) {
960
960
while (g -> g_entryblock && g -> g_entryblock -> b_iused == 0 ) {
961
961
g -> g_entryblock = g -> g_entryblock -> b_next ;
962
962
}
963
+ int next_lbl = get_max_label (g -> g_entryblock ) + 1 ;
963
964
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
964
965
assert (b -> b_iused > 0 );
965
966
for (int i = 0 ; i < b -> b_iused ; i ++ ) {
@@ -969,7 +970,13 @@ eliminate_empty_basic_blocks(cfg_builder *g) {
969
970
while (target -> b_iused == 0 ) {
970
971
target = target -> b_next ;
971
972
}
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
+ }
973
980
assert (instr -> i_target && instr -> i_target -> b_iused > 0 );
974
981
}
975
982
}
You can’t perform that action at this time.
0 commit comments