@@ -2754,12 +2754,13 @@ compiler_if(struct compiler *c, stmt_ty s)
2754
2754
static int
2755
2755
compiler_for (struct compiler * c , stmt_ty s )
2756
2756
{
2757
- basicblock * start , * cleanup , * end ;
2757
+ basicblock * start , * body , * cleanup , * end ;
2758
2758
2759
2759
start = compiler_new_block (c );
2760
+ body = compiler_new_block (c );
2760
2761
cleanup = compiler_new_block (c );
2761
2762
end = compiler_new_block (c );
2762
- if (start == NULL || end == NULL || cleanup == NULL ) {
2763
+ if (start == NULL || body == NULL || end == NULL || cleanup == NULL ) {
2763
2764
return 0 ;
2764
2765
}
2765
2766
if (!compiler_push_fblock (c , FOR_LOOP , start , end , NULL )) {
@@ -2769,6 +2770,7 @@ compiler_for(struct compiler *c, stmt_ty s)
2769
2770
ADDOP (c , GET_ITER );
2770
2771
compiler_use_next_block (c , start );
2771
2772
ADDOP_JUMP (c , FOR_ITER , cleanup );
2773
+ compiler_use_next_block (c , body );
2772
2774
VISIT (c , expr , s -> v .For .target );
2773
2775
VISIT_SEQ (c , stmt , s -> v .For .body );
2774
2776
ADDOP_JUMP (c , JUMP_ABSOLUTE , start );
@@ -5953,7 +5955,7 @@ dump_basicblock(const basicblock *b)
5953
5955
5954
5956
5955
5957
static int
5956
- normalize_basic_block (basicblock * bb ) ;
5958
+ normalize_cfg (basicblock * bb );
5957
5959
5958
5960
static int
5959
5961
optimize_cfg (struct assembler * a , PyObject * consts );
@@ -5981,10 +5983,8 @@ assemble(struct compiler *c, int addNone)
5981
5983
ADDOP (c , RETURN_VALUE );
5982
5984
}
5983
5985
5984
- for (b = c -> u -> u_blocks ; b != NULL ; b = b -> b_list ) {
5985
- if (normalize_basic_block (b )) {
5986
- goto error ;
5987
- }
5986
+ if (normalize_cfg (c -> u -> u_blocks )) {
5987
+ goto error ;
5988
5988
}
5989
5989
5990
5990
if (ensure_exits_have_lineno (c )) {
@@ -6388,7 +6388,8 @@ normalize_basic_block(basicblock *bb) {
6388
6388
case RAISE_VARARGS :
6389
6389
case RERAISE :
6390
6390
bb -> b_exit = 1 ;
6391
- /* fall through */
6391
+ bb -> b_nofallthrough = 1 ;
6392
+ break ;
6392
6393
case JUMP_ABSOLUTE :
6393
6394
case JUMP_FORWARD :
6394
6395
bb -> b_nofallthrough = 1 ;
@@ -6397,10 +6398,27 @@ normalize_basic_block(basicblock *bb) {
6397
6398
case POP_JUMP_IF_TRUE :
6398
6399
case JUMP_IF_FALSE_OR_POP :
6399
6400
case JUMP_IF_TRUE_OR_POP :
6401
+ case FOR_ITER :
6400
6402
if (i != bb -> b_iused - 1 ) {
6401
6403
PyErr_SetString (PyExc_SystemError , "malformed control flow graph." );
6402
6404
return -1 ;
6403
6405
}
6406
+ /* Skip over empty basic blocks. */
6407
+ while (bb -> b_instr [i ].i_target -> b_iused == 0 ) {
6408
+ bb -> b_instr [i ].i_target = bb -> b_instr [i ].i_target -> b_next ;
6409
+ }
6410
+
6411
+ }
6412
+ }
6413
+ return 0 ;
6414
+ }
6415
+
6416
+
6417
+ static int
6418
+ normalize_cfg (basicblock * b ) {
6419
+ for (; b != NULL ; b = b -> b_list ) {
6420
+ if (normalize_basic_block (b )) {
6421
+ return -1 ;
6404
6422
}
6405
6423
}
6406
6424
return 0 ;
@@ -6490,15 +6508,7 @@ optimize_cfg(struct assembler *a, PyObject *consts)
6490
6508
6491
6509
static int
6492
6510
is_exit_without_lineno (basicblock * b ) {
6493
- if (!b -> b_exit ) {
6494
- return 0 ;
6495
- }
6496
- for (int i = 0 ; i < b -> b_iused ; i ++ ) {
6497
- if (b -> b_instr [i ].i_lineno >= 0 ) {
6498
- return 0 ;
6499
- }
6500
- }
6501
- return 1 ;
6511
+ return b -> b_exit && b -> b_instr [0 ].i_lineno < 0 ;
6502
6512
}
6503
6513
6504
6514
/* PEP 626 mandates that the f_lineno of a frame is correct
0 commit comments