@@ -128,10 +128,11 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
128128 block = block_for_inst (ir, idx)
129129 inline_into_block! (state, block)
130130
131- if ! isempty (inlinee_cfg. blocks[1 ]. preds)
131+ if length (inlinee_cfg. blocks[1 ]. preds) > 1
132132 need_split_before = true
133+ else
134+ @assert inlinee_cfg. blocks[1 ]. preds[1 ] == 0
133135 end
134-
135136 last_block_idx = last (state. cfg. blocks[block]. stmts)
136137 if false # TODO : ((idx+1) == last_block_idx && isa(ir[SSAValue(last_block_idx)], GotoNode))
137138 need_split = false
@@ -168,12 +169,18 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
168169 end
169170 new_block_range = (length (state. new_cfg_blocks)- length (inlinee_cfg. blocks)+ 1 ): length (state. new_cfg_blocks)
170171
171- # Fixup the edges of the newely added blocks
172+ # Fixup the edges of the newly added blocks
172173 for (old_block, new_block) in enumerate (bb_rename_range)
173174 if old_block != 1 || need_split_before
174175 p = state. new_cfg_blocks[new_block]. preds
175176 let bb_rename_range = bb_rename_range
176177 map! (p, p) do old_pred_block
178+ # the meaning of predecessor 0 depends on the block we encounter it:
179+ # - in the first block, it represents the function entry and so needs to be re-mapped
180+ if old_block == 1 && old_pred_block == 0
181+ return first (bb_rename_range) - 1
182+ end
183+ # - elsewhere, it represents external control-flow from a caught exception which is un-affected by inlining
177184 return old_pred_block == 0 ? 0 : bb_rename_range[old_pred_block]
178185 end
179186 end
@@ -188,10 +195,6 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
188195 end
189196 end
190197
191- if need_split_before
192- push! (state. new_cfg_blocks[first (bb_rename_range)]. preds, first (bb_rename_range)- 1 )
193- end
194-
195198 any_edges = false
196199 for (old_block, new_block) in enumerate (bb_rename_range)
197200 if (length (state. new_cfg_blocks[new_block]. succs) == 0 )
@@ -437,7 +440,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
437440 else
438441 bb_offset, post_bb_id = popfirst! (todo_bbs)
439442 # This implements the need_split_before flag above
440- need_split_before = ! isempty (item. ir. cfg. blocks[1 ]. preds)
443+ need_split_before = length (item. ir. cfg. blocks[1 ]. preds) > 1
441444 if need_split_before
442445 finish_current_bb! (compact, 0 )
443446 end
0 commit comments