@@ -126,10 +126,11 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
126126 block = block_for_inst (ir, idx)
127127 inline_into_block! (state, block)
128128
129- if ! isempty (inlinee_cfg. blocks[1 ]. preds)
129+ if length (inlinee_cfg. blocks[1 ]. preds) > 1
130130 need_split_before = true
131+ else
132+ @assert inlinee_cfg. blocks[1 ]. preds[1 ] == 0
131133 end
132-
133134 last_block_idx = last (state. cfg. blocks[block]. stmts)
134135 if false # TODO : ((idx+1) == last_block_idx && isa(ir[SSAValue(last_block_idx)], GotoNode))
135136 need_split = false
@@ -166,12 +167,18 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
166167 end
167168 new_block_range = (length (state. new_cfg_blocks)- length (inlinee_cfg. blocks)+ 1 ): length (state. new_cfg_blocks)
168169
169- # Fixup the edges of the newely added blocks
170+ # Fixup the edges of the newly added blocks
170171 for (old_block, new_block) in enumerate (bb_rename_range)
171172 if old_block != 1 || need_split_before
172173 p = state. new_cfg_blocks[new_block]. preds
173174 let bb_rename_range = bb_rename_range
174175 map! (p, p) do old_pred_block
176+ # the meaning of predecessor 0 depends on the block we encounter it:
177+ # - in the first block, it represents the function entry and so needs to be re-mapped
178+ if old_block == 1 && old_pred_block == 0
179+ return first (bb_rename_range) - 1
180+ end
181+ # - elsewhere, it represents external control-flow from a caught exception which is un-affected by inlining
175182 return old_pred_block == 0 ? 0 : bb_rename_range[old_pred_block]
176183 end
177184 end
@@ -186,10 +193,6 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
186193 end
187194 end
188195
189- if need_split_before
190- push! (state. new_cfg_blocks[first (bb_rename_range)]. preds, first (bb_rename_range)- 1 )
191- end
192-
193196 any_edges = false
194197 for (old_block, new_block) in enumerate (bb_rename_range)
195198 if (length (state. new_cfg_blocks[new_block]. succs) == 0 )
@@ -399,7 +402,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
399402 else
400403 bb_offset, post_bb_id = popfirst! (todo_bbs)
401404 # This implements the need_split_before flag above
402- need_split_before = ! isempty (item. ir. cfg. blocks[1 ]. preds)
405+ need_split_before = length (item. ir. cfg. blocks[1 ]. preds) > 1
403406 if need_split_before
404407 finish_current_bb! (compact, 0 )
405408 end
0 commit comments