Skip to content

Commit

Permalink
[release/9.0] [mono] Fix crash in emit_llvmonly_handler_start (#107590)
Browse files Browse the repository at this point in the history
* Fix crash in emit_llvmonly_handler_start

Do not try to emit branch when target_bb is not set

* Feedback

---------

Co-authored-by: Radek Doulik <[email protected]>
Co-authored-by: Larry Ewing <[email protected]>
Co-authored-by: Jeff Schwartz <[email protected]>
  • Loading branch information
4 people authored Sep 16, 2024
1 parent 3de60e8 commit e6a4f1b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5617,6 +5617,17 @@ scalar_op_from_vector_op_process_result (ScalarOpFromVectorOpCtx *sctx, LLVMValu
return vector_from_scalar (sctx->ctx, sctx->return_type, result);
}

static gboolean bb_needs_call_handler_target(MonoBasicBlock *bb, EmitContext *ctx)
{
if (ctx->cfg->interp_entry_only || !(bb->region != -1 && (bb->flags & BB_EXCEPTION_HANDLER)))
return FALSE;

if (ctx->cfg->deopt && MONO_REGION_FLAGS (bb->region) == MONO_EXCEPTION_CLAUSE_FILTER)
return FALSE;

return TRUE;
}

static void
emit_llvmonly_handler_start (EmitContext *ctx, MonoBasicBlock *bb, LLVMBasicBlockRef cbb)
{
Expand All @@ -5636,8 +5647,13 @@ emit_llvmonly_handler_start (EmitContext *ctx, MonoBasicBlock *bb, LLVMBasicBloc
}
}

LLVMBuilderRef handler_builder = create_builder (ctx);
LLVMBasicBlockRef target_bb = ctx->bblocks [bb->block_num].call_handler_target_bb;
if (!target_bb) {
g_assert(!bb_needs_call_handler_target (bb, ctx));
return;
}

LLVMBuilderRef handler_builder = create_builder (ctx);
LLVMPositionBuilderAtEnd (handler_builder, target_bb);

// Make the handler code end with a jump to cbb
Expand Down Expand Up @@ -13406,10 +13422,7 @@ emit_method_inner (EmitContext *ctx)
int clause_index;
char name [128];

if (ctx->cfg->interp_entry_only || !(bb->region != -1 && (bb->flags & BB_EXCEPTION_HANDLER)))
continue;

if (ctx->cfg->deopt && MONO_REGION_FLAGS (bb->region) == MONO_EXCEPTION_CLAUSE_FILTER)
if (!bb_needs_call_handler_target(bb, ctx))
continue;

clause_index = MONO_REGION_CLAUSE_INDEX (bb->region);
Expand Down

0 comments on commit e6a4f1b

Please sign in to comment.