@@ -364,7 +364,7 @@ fn inline_one(
364364 // Prepare for translating the actual instructions by inserting the inlined
365365 // blocks into the caller's layout in the same order that they appear in the
366366 // callee.
367- let last_inlined_block = inline_block_layout ( func, call_block, callee, & entity_map) ;
367+ let mut last_inlined_block = inline_block_layout ( func, call_block, callee, & entity_map) ;
368368
369369 // Translate each instruction from the callee into the caller,
370370 // appending them to their associated block in the caller.
@@ -492,6 +492,18 @@ fn inline_one(
492492 // empty blocks from the caller's layout.
493493 for block in entity_map. iter_inlined_blocks ( func) {
494494 if func. layout . is_block_inserted ( block) && func. layout . first_inst ( block) . is_none ( ) {
495+ log:: trace!( "removing unreachable inlined block from layout: {block}" ) ;
496+
497+ // If the block being removed is our last-inlined block, then back
498+ // it up to the previous block in the layout, which will be the new
499+ // last-inlined block after this one's removal.
500+ if block == last_inlined_block {
501+ last_inlined_block = func. layout . prev_block ( last_inlined_block) . expect (
502+ "there will always at least be the block that contained the call we are \
503+ inlining",
504+ ) ;
505+ }
506+
495507 func. layout . remove_block ( block) ;
496508 }
497509 }
@@ -517,6 +529,10 @@ fn inline_one(
517529 fixup_inlined_call_exception_tables ( allocs, func, call_exception_table) ;
518530 }
519531
532+ debug_assert ! (
533+ func. layout. is_block_inserted( last_inlined_block) ,
534+ "last_inlined_block={last_inlined_block} should be inserted in the layout"
535+ ) ;
520536 last_inlined_block
521537}
522538
@@ -972,18 +988,24 @@ fn inline_block_layout(
972988 callee : & ir:: Function ,
973989 entity_map : & EntityMap ,
974990) -> ir:: Block {
991+ debug_assert ! ( func. layout. is_block_inserted( call_block) ) ;
992+
975993 // Iterate over callee blocks in layout order, inserting their associated
976994 // inlined block into the caller's layout.
977995 let mut prev_inlined_block = call_block;
978996 let mut next_callee_block = callee. layout . entry_block ( ) ;
979997 while let Some ( callee_block) = next_callee_block {
998+ debug_assert ! ( func. layout. is_block_inserted( prev_inlined_block) ) ;
999+
9801000 let inlined_block = entity_map. inlined_block ( callee_block) ;
9811001 func. layout
9821002 . insert_block_after ( inlined_block, prev_inlined_block) ;
9831003
9841004 prev_inlined_block = inlined_block;
9851005 next_callee_block = callee. layout . next_block ( callee_block) ;
9861006 }
1007+
1008+ debug_assert ! ( func. layout. is_block_inserted( prev_inlined_block) ) ;
9871009 prev_inlined_block
9881010}
9891011
0 commit comments