Просмотр исходного кода

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.
TianlongLiang 2 лет назад
Родитель
Сommit
059fbfc252
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      core/iwasm/compilation/aot_emit_control.c

+ 9 - 2
core/iwasm/compilation/aot_emit_control.c

@@ -281,7 +281,7 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx,
                                         AOTBlock *block)
                                         AOTBlock *block)
 {
 {
     uint32 i, param_index;
     uint32 i, param_index;
-    LLVMValueRef value;
+    LLVMValueRef value, br_inst;
     uint64 size;
     uint64 size;
     char name[32];
     char name[32];
     LLVMBasicBlockRef block_curr = CURR_BLOCK();
     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
         /* Pop param values from current block's
          * value stack and add to param phis.
          * value stack and add to param phis.