Skip to content

Conversation

@FromLiQg
Copy link
Contributor

[1] In function jit_compile_op_call_indirect: ignoring to detect error after generate instruction or register
https://github.com/wasm-micro-runtime/wamr-internal-dev/issues/423
[2] In function jit_cc_init: ingore to free entry_block and exit_block
https://github.com/wasm-micro-runtime/wamr-internal-dev/issues/422

Comment on lines 383 to 393
if (!(entry_block = jit_cc_new_basic_block(cc, 0))
|| !(exit_block = jit_cc_new_basic_block(cc, 0)))
goto fail;
goto fail2;

if (!(cc->exce_basic_blocks =
jit_calloc(sizeof(JitBasicBlock *) * JIT_EXCE_NUM)))
goto fail;
goto fail2;

if (!(cc->incoming_insns_for_exec_bbs =
jit_calloc(sizeof(JitIncomingInsnList) * JIT_EXCE_NUM)))
goto fail;
goto fail2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks very strange, as it goto upper failed label firstly, normally we should goto fail1 firstly but not goto fail2. How about changing to:

    if (!(entry_block = jit_cc_new_basic_block(cc, 0)))
        goto fail;

    if (!(exit_block = jit_cc_new_basic_block(cc, 0))) {
        jit_basic_block_delete(entry_block);
        goto fail;
    }

    /* Record the entry and exit labels, whose indexes must be 0 and 1
       respectively.  */
    cc->entry_label = jit_basic_block_label(entry_block);
    cc->exit_label = jit_basic_block_label(exit_block);
    bh_assert(jit_reg_no(cc->entry_label) == 0
              && jit_reg_no(cc->exit_label) == 1);

    if (!(cc->exce_basic_blocks =
              jit_calloc(sizeof(JitBasicBlock *) * JIT_EXCE_NUM)))
        goto fail;

    if (!(cc->incoming_insns_for_exec_bbs =
              jit_calloc(sizeof(JitIncomingInsnList) * JIT_EXCE_NUM)))
        goto fail;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have changed it.

arg_regs[5] = argv;

if (!jit_emit_callnative(cc, jit_call_indirect, native_ret, arg_regs, 6)) {
if (jit_get_last_error(cc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we should add jit_get_last_error(cc) here, if not, which error will it cause?

Copy link
Contributor Author

@FromLiQg FromLiQg Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Before calling jit_emit_callnative, we call pack_argv(cc).
  2. It may set error in function pack_argv.
  3. If we continue to call jit_emit_callnative after calling pack_argv(cc) failed, it will cause bh_assert failed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So had better move check into pack_argv:

static JitReg
pack_argv(JitCompContext *cc)
{
   ...
   if (jit_get_last_error(cc))
       return 0;
   return argv;
}

And add check when calling pack_argv:

if (!(argv = pack_argv(cc)))
    goto fail;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for you sugestion. I have changed it.

GEN_INSN(CMP, cc->cmp_reg, native_ret, NEW_CONST(I32, 0));
if (!jit_emit_exception(cc, JIT_EXCE_ALREADY_THROWN, JIT_OP_BEQ,
cc->cmp_reg, NULL)) {
if (jit_get_last_error(cc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This code has been deleted and found unnecessary.

@FromLiQg FromLiQg closed this Sep 16, 2022
@FromLiQg FromLiQg reopened this Sep 16, 2022
@FromLiQg FromLiQg closed this Sep 22, 2022
and fix bh_assert failed in jit_emit_function.c
@FromLiQg FromLiQg reopened this Sep 22, 2022
@wenyongh wenyongh merged commit 32d2d16 into bytecodealliance:main Sep 22, 2022
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
- Add checks for `pack_argv`
- Fix the checks in creating cc entry/exit basic blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants