@@ -505,6 +505,21 @@ no_redundant_jumps(cfg_builder *g) {
505505 return true;
506506}
507507
508+ static bool
509+ all_exits_have_lineno (basicblock * entryblock ) {
510+ for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
511+ for (int i = 0 ; i < b -> b_iused ; i ++ ) {
512+ cfg_instr * instr = & b -> b_instr [i ];
513+ if (instr -> i_opcode == RETURN_VALUE ) {
514+ if (instr -> i_loc .lineno < 0 ) {
515+ assert (0 );
516+ return false;
517+ }
518+ }
519+ }
520+ }
521+ return true;
522+ }
508523#endif
509524
510525/***** CFG preprocessing (jump targets and exceptions) *****/
@@ -2378,34 +2393,6 @@ propagate_line_numbers(basicblock *entryblock) {
23782393 }
23792394}
23802395
2381- /* Make sure that all returns have a line number, even if early passes
2382- * have failed to propagate a correct line number.
2383- * The resulting line number may not be correct according to PEP 626,
2384- * but should be "good enough", and no worse than in older versions. */
2385- static void
2386- guarantee_lineno_for_exits (basicblock * entryblock , int firstlineno ) {
2387- int lineno = firstlineno ;
2388- assert (lineno > 0 );
2389- for (basicblock * b = entryblock ; b != NULL ; b = b -> b_next ) {
2390- cfg_instr * last = basicblock_last_instr (b );
2391- if (last == NULL ) {
2392- continue ;
2393- }
2394- if (last -> i_loc .lineno < 0 ) {
2395- if (last -> i_opcode == RETURN_VALUE ) {
2396- for (int i = 0 ; i < b -> b_iused ; i ++ ) {
2397- assert (b -> b_instr [i ].i_loc .lineno < 0 );
2398-
2399- b -> b_instr [i ].i_loc .lineno = lineno ;
2400- }
2401- }
2402- }
2403- else {
2404- lineno = last -> i_loc .lineno ;
2405- }
2406- }
2407- }
2408-
24092396static int
24102397resolve_line_numbers (cfg_builder * g , int firstlineno )
24112398{
@@ -2434,7 +2421,7 @@ _PyCfg_OptimizeCodeUnit(cfg_builder *g, PyObject *consts, PyObject *const_cache,
24342421 insert_superinstructions (g );
24352422
24362423 RETURN_IF_ERROR (push_cold_blocks_to_end (g ));
2437- guarantee_lineno_for_exits ( g -> g_entryblock , firstlineno );
2424+ assert ( all_exits_have_lineno ( g -> g_entryblock ) );
24382425 RETURN_IF_ERROR (resolve_line_numbers (g , firstlineno ));
24392426 return SUCCESS ;
24402427}
0 commit comments