Fix potential issue in aot compiler when translating block opcodes (#2622)

The LLVM zext IR may be inserted after the terminator of a basic block
when popping the arguments of a wasm block. Change to insert the
zext IR before the terminator of the basic block to resolve the issue.

Reported in #2620.
This commit is contained in:
TianlongLiang 2023-10-08 09:17:54 +08:00 committed by GitHub
parent 7c22bde8dc
commit 059fbfc252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -281,7 +281,7 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
AOTBlock *block)
{
uint32 i, param_index;
LLVMValueRef value;
LLVMValueRef value, br_inst;
uint64 size;
char name[32];
LLVMBasicBlockRef block_curr = CURR_BLOCK();
@ -329,7 +329,14 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
}
}
}
SET_BUILDER_POS(block_curr);
/* At this point, the branch instruction was already built to jump to
* the new BB, to avoid generating zext instruction from the popped
* operand that would come after branch instruction, we should position
* the builder before the last branch instruction */
br_inst = LLVMGetLastInstruction(block_curr);
bh_assert(LLVMGetInstructionOpcode(br_inst) == LLVMBr);
LLVMPositionBuilderBefore(comp_ctx->builder, br_inst);
/* Pop param values from current block's
* value stack and add to param phis.