@@ -292,6 +292,7 @@ write_location_info_entry(struct assembler* a, location loc, int isize)
292292 RETURN_IF_ERROR (_PyBytes_Resize (& a -> a_linetable , len * 2 ));
293293 }
294294 if (loc .lineno < 0 ) {
295+ assert (loc .lineno == NO_LOCATION .lineno );
295296 write_location_info_none (a , isize );
296297 return SUCCESS ;
297298 }
@@ -342,19 +343,19 @@ assemble_location_info(struct assembler *a, instr_sequence *instrs,
342343{
343344 a -> a_lineno = firstlineno ;
344345 location loc = NO_LOCATION ;
345- int size = 0 ;
346- // The last location should not be NEXT_LOCATION, but don't crash non-debug builds
347- if (same_location (instrs -> s_instrs [instrs -> s_used - 1 ].i_loc , NEXT_LOCATION )) {
348- assert (0 && "last instruction has NEXT_LOCATION" );
349- instrs -> s_instrs [instrs -> s_used - 1 ].i_loc = NO_LOCATION ;
350- }
351- for (int i = instrs -> s_used - 1 ; i > 0 ; i -- ) {
346+ for (int i = instrs -> s_used - 1 ; i >= 0 ; i -- ) {
352347 instruction * instr = & instrs -> s_instrs [i ];
353- if (same_location (instr [-1 ].i_loc , NEXT_LOCATION )) {
354- assert (!IS_TERMINATOR_OPCODE (instr [-1 ].i_opcode ));
355- instr [-1 ].i_loc = instr -> i_loc ;
348+ if (same_location (instr -> i_loc , NEXT_LOCATION )) {
349+ if (IS_TERMINATOR_OPCODE (instr -> i_opcode )) {
350+ instr -> i_loc = NO_LOCATION ;
351+ }
352+ else {
353+ assert (i < instrs -> s_used - 1 );
354+ instr -> i_loc = instr [1 ].i_loc ;
355+ }
356356 }
357357 }
358+ int size = 0 ;
358359 for (int i = 0 ; i < instrs -> s_used ; i ++ ) {
359360 instruction * instr = & instrs -> s_instrs [i ];
360361 if (!same_location (loc , instr -> i_loc )) {
0 commit comments