@@ -890,7 +890,7 @@ compiler_copy_block(struct compiler *c, basicblock *block)
890
890
* a block can only have one fallthrough predecessor.
891
891
*/
892
892
assert (block -> b_nofallthrough );
893
- basicblock * result = compiler_next_block (c );
893
+ basicblock * result = compiler_new_block (c );
894
894
if (result == NULL ) {
895
895
return NULL ;
896
896
}
@@ -7567,8 +7567,9 @@ normalize_basic_block(basicblock *bb);
7567
7567
static int
7568
7568
optimize_cfg (struct compiler * c , struct assembler * a , PyObject * consts );
7569
7569
7570
+ /* Duplicates exit BBs, so that line numbers can be propagated to them */
7570
7571
static int
7571
- ensure_exits_have_lineno (struct compiler * c );
7572
+ duplicate_exits_without_lineno (struct compiler * c );
7572
7573
7573
7574
static int
7574
7575
extend_block (basicblock * bb );
@@ -7710,10 +7711,10 @@ guarantee_lineno_for_exits(struct assembler *a, int firstlineno) {
7710
7711
}
7711
7712
struct instr * last = & b -> b_instr [b -> b_iused - 1 ];
7712
7713
if (last -> i_lineno < 0 ) {
7713
- if (last -> i_opcode == RETURN_VALUE )
7714
- {
7714
+ if (last -> i_opcode == RETURN_VALUE ) {
7715
7715
for (int i = 0 ; i < b -> b_iused ; i ++ ) {
7716
7716
assert (b -> b_instr [i ].i_lineno < 0 );
7717
+
7717
7718
b -> b_instr [i ].i_lineno = lineno ;
7718
7719
}
7719
7720
}
@@ -7769,6 +7770,9 @@ fix_cell_offsets(struct compiler *c, basicblock *entryblock, int *fixedmap)
7769
7770
return numdropped ;
7770
7771
}
7771
7772
7773
+ static void
7774
+ propagate_line_numbers (struct assembler * a );
7775
+
7772
7776
static PyCodeObject *
7773
7777
assemble (struct compiler * c , int addNone )
7774
7778
{
@@ -7801,10 +7805,6 @@ assemble(struct compiler *c, int addNone)
7801
7805
}
7802
7806
}
7803
7807
7804
- if (ensure_exits_have_lineno (c )) {
7805
- return NULL ;
7806
- }
7807
-
7808
7808
nblocks = 0 ;
7809
7809
entryblock = NULL ;
7810
7810
for (b = c -> u -> u_blocks ; b != NULL ; b = b -> b_list ) {
@@ -7861,8 +7861,11 @@ assemble(struct compiler *c, int addNone)
7861
7861
if (optimize_cfg (c , & a , consts )) {
7862
7862
goto error ;
7863
7863
}
7864
+ if (duplicate_exits_without_lineno (c )) {
7865
+ return NULL ;
7866
+ }
7867
+ propagate_line_numbers (& a );
7864
7868
guarantee_lineno_for_exits (& a , c -> u -> u_firstlineno );
7865
-
7866
7869
int maxdepth = stackdepth (c );
7867
7870
if (maxdepth < 0 ) {
7868
7871
goto error ;
@@ -8365,6 +8368,7 @@ clean_basic_block(basicblock *bb) {
8365
8368
}
8366
8369
}
8367
8370
}
8371
+
8368
8372
}
8369
8373
if (dest != src ) {
8370
8374
bb -> b_instr [dest ] = bb -> b_instr [src ];
@@ -8479,7 +8483,7 @@ eliminate_empty_basic_blocks(basicblock *entry) {
8479
8483
* but has no impact on the generated line number events.
8480
8484
*/
8481
8485
static void
8482
- propogate_line_numbers (struct assembler * a ) {
8486
+ propagate_line_numbers (struct assembler * a ) {
8483
8487
for (basicblock * b = a -> a_entry ; b != NULL ; b = b -> b_next ) {
8484
8488
if (b -> b_iused == 0 ) {
8485
8489
continue ;
@@ -8544,6 +8548,11 @@ optimize_cfg(struct compiler *c, struct assembler *a, PyObject *consts)
8544
8548
clean_basic_block (b );
8545
8549
assert (b -> b_predecessors == 0 );
8546
8550
}
8551
+ for (basicblock * b = c -> u -> u_blocks ; b != NULL ; b = b -> b_list ) {
8552
+ if (extend_block (b )) {
8553
+ return -1 ;
8554
+ }
8555
+ }
8547
8556
if (mark_reachable (a )) {
8548
8557
return -1 ;
8549
8558
}
@@ -8581,7 +8590,6 @@ optimize_cfg(struct compiler *c, struct assembler *a, PyObject *consts)
8581
8590
if (maybe_empty_blocks ) {
8582
8591
eliminate_empty_basic_blocks (a -> a_entry );
8583
8592
}
8584
- propogate_line_numbers (a );
8585
8593
return 0 ;
8586
8594
}
8587
8595
@@ -8600,7 +8608,7 @@ is_exit_without_lineno(basicblock *b) {
8600
8608
* copy the line number from the sole predecessor block.
8601
8609
*/
8602
8610
static int
8603
- ensure_exits_have_lineno (struct compiler * c )
8611
+ duplicate_exits_without_lineno (struct compiler * c )
8604
8612
{
8605
8613
basicblock * entry = NULL ;
8606
8614
/* Copy all exit blocks without line number that are targets of a jump.
@@ -8616,20 +8624,21 @@ ensure_exits_have_lineno(struct compiler *c)
8616
8624
continue ;
8617
8625
}
8618
8626
basicblock * target = b -> b_instr [b -> b_iused - 1 ].i_target ;
8619
- if (is_exit_without_lineno (target )) {
8627
+ if (is_exit_without_lineno (target ) && target -> b_predecessors > 1 ) {
8620
8628
basicblock * new_target = compiler_copy_block (c , target );
8621
8629
if (new_target == NULL ) {
8622
8630
return -1 ;
8623
8631
}
8624
8632
COPY_INSTR_LOC (b -> b_instr [b -> b_iused - 1 ], new_target -> b_instr [0 ]);
8625
8633
b -> b_instr [b -> b_iused - 1 ].i_target = new_target ;
8634
+ target -> b_predecessors -- ;
8635
+ new_target -> b_predecessors = 1 ;
8636
+ new_target -> b_next = target -> b_next ;
8637
+ target -> b_next = new_target ;
8626
8638
}
8627
8639
}
8628
8640
}
8629
8641
assert (entry != NULL );
8630
- if (is_exit_without_lineno (entry )) {
8631
- entry -> b_instr [0 ].i_lineno = c -> u -> u_firstlineno ;
8632
- }
8633
8642
/* Eliminate empty blocks */
8634
8643
for (basicblock * b = c -> u -> u_blocks ; b != NULL ; b = b -> b_list ) {
8635
8644
while (b -> b_next && b -> b_next -> b_iused == 0 ) {
0 commit comments