@@ -1652,10 +1652,6 @@ cfg_builder_addop_j(cfg_builder *g, struct location loc,
1652
1652
#define ADDOP_INPLACE (C , LOC , BINOP ) \
1653
1653
RETURN_IF_FALSE(addop_binary((C), (LOC), (BINOP), true))
1654
1654
1655
- /* VISIT and VISIT_SEQ takes an ASDL type as their second argument. They use
1656
- the ASDL name to synthesize the name of the C type and the visit function.
1657
- */
1658
-
1659
1655
#define ADD_YIELD_FROM (C , LOC , await ) \
1660
1656
RETURN_IF_FALSE(compiler_add_yield_from((C), (LOC), (await)))
1661
1657
@@ -1665,6 +1661,10 @@ cfg_builder_addop_j(cfg_builder *g, struct location loc,
1665
1661
#define ADDOP_YIELD (C , LOC ) \
1666
1662
RETURN_IF_FALSE(addop_yield((C), (LOC)))
1667
1663
1664
+ /* VISIT and VISIT_SEQ takes an ASDL type as their second argument. They use
1665
+ the ASDL name to synthesize the name of the C type and the visit function.
1666
+ */
1667
+
1668
1668
#define VISIT (C , TYPE , V ) {\
1669
1669
if (!compiler_visit_ ## TYPE((C), (V))) \
1670
1670
return 0; \
@@ -3307,6 +3307,18 @@ compiler_continue(struct compiler *c, struct location loc)
3307
3307
}
3308
3308
3309
3309
3310
+ static struct location
3311
+ last_location_in_body (asdl_stmt_seq * stmts )
3312
+ {
3313
+ for (int i = asdl_seq_LEN (stmts ) - 1 ; i >= 0 ; i ++ ) {
3314
+ struct location loc = LOC ((stmt_ty )asdl_seq_GET (stmts , i ));
3315
+ if (loc .lineno > 0 ) {
3316
+ return loc ;
3317
+ }
3318
+ }
3319
+ return NO_LOCATION ;
3320
+ }
3321
+
3310
3322
/* Code generated for "try: <body> finally: <finalbody>" is as follows:
3311
3323
3312
3324
SETUP_FINALLY L
@@ -3362,6 +3374,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
3362
3374
ADDOP (c , NO_LOCATION , POP_BLOCK );
3363
3375
compiler_pop_fblock (c , FINALLY_TRY , body );
3364
3376
VISIT_SEQ (c , stmt , s -> v .Try .finalbody );
3377
+
3365
3378
ADDOP_JUMP (c , NO_LOCATION , JUMP , exit );
3366
3379
/* `finally` block */
3367
3380
@@ -3374,6 +3387,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
3374
3387
if (!compiler_push_fblock (c , loc , FINALLY_END , end , NO_LABEL , NULL ))
3375
3388
return 0 ;
3376
3389
VISIT_SEQ (c , stmt , s -> v .Try .finalbody );
3390
+ loc = last_location_in_body (s -> v .Try .finalbody );
3377
3391
compiler_pop_fblock (c , FINALLY_END , end );
3378
3392
3379
3393
ADDOP_I (c , loc , RERAISE , 0 ); // CHANGED
@@ -3412,6 +3426,7 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
3412
3426
ADDOP (c , NO_LOCATION , POP_BLOCK );
3413
3427
compiler_pop_fblock (c , FINALLY_TRY , body );
3414
3428
VISIT_SEQ (c , stmt , s -> v .TryStar .finalbody );
3429
+
3415
3430
ADDOP_JUMP (c , NO_LOCATION , JUMP , exit );
3416
3431
3417
3432
/* `finally` block */
@@ -3425,6 +3440,8 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
3425
3440
return 0 ;
3426
3441
}
3427
3442
VISIT_SEQ (c , stmt , s -> v .TryStar .finalbody );
3443
+ loc = last_location_in_body (s -> v .Try .finalbody );
3444
+
3428
3445
compiler_pop_fblock (c , FINALLY_END , end );
3429
3446
ADDOP_I (c , loc , RERAISE , 0 ); // CHANGED
3430
3447
0 commit comments