Skip to content

Commit 826ae6e

Browse files
authored
Prevent BuildPhi from encountering a null llvm_entry_block (#4663)
There is a scenario where `aot_compile_op_block()` does not prepare a block for `if`. As a result, the return value of `LLVMBuildPhi()` in `push_aot_block_to_stack_and_pass_params()` will be dangling, leading to a memory leak as it cannot be released.
1 parent 163acd2 commit 826ae6e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

core/iwasm/compilation/aot_emit_control.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,17 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
495495

496496
/* Create param phis */
497497
for (i = 0; i < block->param_count; i++) {
498-
SET_BUILDER_POS(block->llvm_entry_block);
499-
snprintf(name, sizeof(name), "%s%d_phi%d",
500-
block_name_prefix[block->label_type], block->block_index,
501-
i);
502-
if (!(block->param_phis[i] = LLVMBuildPhi(
503-
comp_ctx->builder, TO_LLVM_TYPE(block->param_types[i]),
504-
name))) {
505-
aot_set_last_error("llvm build phi failed.");
506-
goto fail;
498+
if (block->llvm_entry_block) {
499+
SET_BUILDER_POS(block->llvm_entry_block);
500+
snprintf(name, sizeof(name), "%s%d_phi%d",
501+
block_name_prefix[block->label_type],
502+
block->block_index, i);
503+
if (!(block->param_phis[i] = LLVMBuildPhi(
504+
comp_ctx->builder,
505+
TO_LLVM_TYPE(block->param_types[i]), name))) {
506+
aot_set_last_error("llvm build phi failed.");
507+
goto fail;
508+
}
507509
}
508510

509511
if (block->label_type == LABEL_TYPE_IF

0 commit comments

Comments
 (0)