@@ -7396,6 +7396,9 @@ mark_cold(basicblock *entryblock) {
7396
7396
return 0 ;
7397
7397
}
7398
7398
7399
+ static int
7400
+ remove_redundant_jumps (cfg_builder * g );
7401
+
7399
7402
static int
7400
7403
push_cold_blocks_to_end (cfg_builder * g , int code_flags ) {
7401
7404
basicblock * entryblock = g -> g_entryblock ;
@@ -7465,6 +7468,12 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
7465
7468
}
7466
7469
assert (b != NULL && b -> b_next == NULL );
7467
7470
b -> b_next = cold_blocks ;
7471
+
7472
+ if (cold_blocks != NULL ) {
7473
+ if (remove_redundant_jumps (g ) < 0 ) {
7474
+ return -1 ;
7475
+ }
7476
+ }
7468
7477
return 0 ;
7469
7478
}
7470
7479
@@ -8269,9 +8278,6 @@ trim_unused_consts(basicblock *entryblock, PyObject *consts);
8269
8278
static int
8270
8279
duplicate_exits_without_lineno (cfg_builder * g );
8271
8280
8272
- static int
8273
- extend_block (basicblock * bb );
8274
-
8275
8281
static int *
8276
8282
build_cellfixedoffsets (struct compiler * c )
8277
8283
{
@@ -8476,6 +8482,21 @@ propagate_line_numbers(basicblock *entryblock);
8476
8482
static void
8477
8483
eliminate_empty_basic_blocks (cfg_builder * g );
8478
8484
8485
+ #ifndef NDEBUG
8486
+ static bool
8487
+ no_redundant_jumps (cfg_builder * g ) {
8488
+ for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
8489
+ struct instr * last = basicblock_last_instr (b );
8490
+ if (last != NULL ) {
8491
+ if (last -> i_opcode == JUMP || last -> i_opcode == JUMP_NO_INTERRUPT ) {
8492
+ assert (last -> i_target != b -> b_next );
8493
+ return false;
8494
+ }
8495
+ }
8496
+ }
8497
+ return true;
8498
+ }
8499
+ #endif
8479
8500
8480
8501
static int
8481
8502
remove_redundant_jumps (cfg_builder * g ) {
@@ -8592,8 +8613,8 @@ assemble(struct compiler *c, int addNone)
8592
8613
if (trim_unused_consts (g -> g_entryblock , consts )) {
8593
8614
goto error ;
8594
8615
}
8595
- if (duplicate_exits_without_lineno (g )) {
8596
- return NULL ;
8616
+ if (duplicate_exits_without_lineno (g ) < 0 ) {
8617
+ goto error ;
8597
8618
}
8598
8619
propagate_line_numbers (g -> g_entryblock );
8599
8620
guarantee_lineno_for_exits (g -> g_entryblock , c -> u -> u_firstlineno );
@@ -8612,10 +8633,6 @@ assemble(struct compiler *c, int addNone)
8612
8633
if (push_cold_blocks_to_end (g , code_flags ) < 0 ) {
8613
8634
goto error ;
8614
8635
}
8615
-
8616
- if (remove_redundant_jumps (g ) < 0 ) {
8617
- goto error ;
8618
- }
8619
8636
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
8620
8637
clean_basic_block (b );
8621
8638
}
@@ -8627,6 +8644,8 @@ assemble(struct compiler *c, int addNone)
8627
8644
goto error ;
8628
8645
}
8629
8646
8647
+ assert (no_redundant_jumps (g ));
8648
+
8630
8649
/* Can't modify the bytecode after computing jump offsets. */
8631
8650
assemble_jump_offsets (g -> g_entryblock );
8632
8651
@@ -9488,7 +9507,7 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
9488
9507
}
9489
9508
}
9490
9509
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9491
- if (extend_block (b )) {
9510
+ if (extend_block (b ) < 0 ) {
9492
9511
return -1 ;
9493
9512
}
9494
9513
}
@@ -9500,7 +9519,7 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
9500
9519
assert (b -> b_predecessors == 0 );
9501
9520
}
9502
9521
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9503
- if (extend_block (b )) {
9522
+ if (extend_block (b ) < 0 ) {
9504
9523
return -1 ;
9505
9524
}
9506
9525
}
@@ -9517,6 +9536,9 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
9517
9536
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9518
9537
clean_basic_block (b );
9519
9538
}
9539
+ if (remove_redundant_jumps (g ) < 0 ) {
9540
+ return -1 ;
9541
+ }
9520
9542
return 0 ;
9521
9543
}
9522
9544
0 commit comments