@@ -7396,6 +7396,9 @@ mark_cold(basicblock *entryblock) {
73967396 return 0 ;
73977397}
73987398
7399+ static int
7400+ remove_redundant_jumps (cfg_builder * g );
7401+
73997402static int
74007403push_cold_blocks_to_end (cfg_builder * g , int code_flags ) {
74017404 basicblock * entryblock = g -> g_entryblock ;
@@ -7465,6 +7468,12 @@ push_cold_blocks_to_end(cfg_builder *g, int code_flags) {
74657468 }
74667469 assert (b != NULL && b -> b_next == NULL );
74677470 b -> b_next = cold_blocks ;
7471+
7472+ if (cold_blocks != NULL ) {
7473+ if (remove_redundant_jumps (g ) < 0 ) {
7474+ return -1 ;
7475+ }
7476+ }
74687477 return 0 ;
74697478}
74707479
@@ -8269,9 +8278,6 @@ trim_unused_consts(basicblock *entryblock, PyObject *consts);
82698278static int
82708279duplicate_exits_without_lineno (cfg_builder * g );
82718280
8272- static int
8273- extend_block (basicblock * bb );
8274-
82758281static int *
82768282build_cellfixedoffsets (struct compiler * c )
82778283{
@@ -8476,6 +8482,21 @@ propagate_line_numbers(basicblock *entryblock);
84768482static void
84778483eliminate_empty_basic_blocks (cfg_builder * g );
84788484
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
84798500
84808501static int
84818502remove_redundant_jumps (cfg_builder * g ) {
@@ -8592,8 +8613,8 @@ assemble(struct compiler *c, int addNone)
85928613 if (trim_unused_consts (g -> g_entryblock , consts )) {
85938614 goto error ;
85948615 }
8595- if (duplicate_exits_without_lineno (g )) {
8596- return NULL ;
8616+ if (duplicate_exits_without_lineno (g ) < 0 ) {
8617+ goto error ;
85978618 }
85988619 propagate_line_numbers (g -> g_entryblock );
85998620 guarantee_lineno_for_exits (g -> g_entryblock , c -> u -> u_firstlineno );
@@ -8612,10 +8633,6 @@ assemble(struct compiler *c, int addNone)
86128633 if (push_cold_blocks_to_end (g , code_flags ) < 0 ) {
86138634 goto error ;
86148635 }
8615-
8616- if (remove_redundant_jumps (g ) < 0 ) {
8617- goto error ;
8618- }
86198636 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
86208637 clean_basic_block (b );
86218638 }
@@ -8627,6 +8644,8 @@ assemble(struct compiler *c, int addNone)
86278644 goto error ;
86288645 }
86298646
8647+ assert (no_redundant_jumps (g ));
8648+
86308649 /* Can't modify the bytecode after computing jump offsets. */
86318650 assemble_jump_offsets (g -> g_entryblock );
86328651
@@ -9488,7 +9507,7 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
94889507 }
94899508 }
94909509 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9491- if (extend_block (b )) {
9510+ if (extend_block (b ) < 0 ) {
94929511 return -1 ;
94939512 }
94949513 }
@@ -9500,7 +9519,7 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
95009519 assert (b -> b_predecessors == 0 );
95019520 }
95029521 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
9503- if (extend_block (b )) {
9522+ if (extend_block (b ) < 0 ) {
95049523 return -1 ;
95059524 }
95069525 }
@@ -9517,6 +9536,9 @@ optimize_cfg(cfg_builder *g, PyObject *consts, PyObject *const_cache)
95179536 for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
95189537 clean_basic_block (b );
95199538 }
9539+ if (remove_redundant_jumps (g ) < 0 ) {
9540+ return -1 ;
9541+ }
95209542 return 0 ;
95219543}
95229544
0 commit comments