-
Notifications
You must be signed in to change notification settings - Fork 749
Fix bugs occurring in Instrument Test #1488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
core/iwasm/fast-jit/jit_ir.c
Outdated
| 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; |
There was a problem hiding this comment.
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;There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Before calling
jit_emit_callnative, we callpack_argv(cc). - It may set error in function
pack_argv. - If we continue to call
jit_emit_callnativeafter callingpack_argv(cc)failed, it will causebh_assertfailed
There was a problem hiding this comment.
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;There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
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.
and fix bh_assert failed in jit_emit_function.c
- Add checks for `pack_argv` - Fix the checks in creating cc entry/exit basic blocks
[1] In function
jit_compile_op_call_indirect: ignoring to detect error after generate instruction or registerhttps://github.com/wasm-micro-runtime/wamr-internal-dev/issues/423
[2] In function
jit_cc_init: ingore to free entry_block and exit_blockhttps://github.com/wasm-micro-runtime/wamr-internal-dev/issues/422