@@ -292,6 +292,7 @@ write_location_info_entry(struct assembler* a, location loc, int isize)
292
292
RETURN_IF_ERROR (_PyBytes_Resize (& a -> a_linetable , len * 2 ));
293
293
}
294
294
if (loc .lineno < 0 ) {
295
+ assert (loc .lineno == NO_LOCATION .lineno );
295
296
write_location_info_none (a , isize );
296
297
return SUCCESS ;
297
298
}
@@ -342,19 +343,19 @@ assemble_location_info(struct assembler *a, instr_sequence *instrs,
342
343
{
343
344
a -> a_lineno = firstlineno ;
344
345
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 -- ) {
352
347
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
+ }
356
356
}
357
357
}
358
+ int size = 0 ;
358
359
for (int i = 0 ; i < instrs -> s_used ; i ++ ) {
359
360
instruction * instr = & instrs -> s_instrs [i ];
360
361
if (!same_location (loc , instr -> i_loc )) {
0 commit comments