Skip to content

Commit 5340e3c

Browse files
authored
Fix sanitizer check issue when both def reg and ref reg are the same (#1226)
Fix issue of instruction like MOV i3, i3
1 parent 96fa546 commit 5340e3c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

core/iwasm/fast-jit/jit_regalloc.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,33 @@ is_alloc_candidate(JitCompContext *cc, JitReg reg)
358358
static void
359359
check_vreg_definition(RegallocContext *rc, JitInsn *insn)
360360
{
361-
unsigned j;
362361
JitRegVec regvec = jit_insn_opnd_regs(insn);
363-
unsigned first_use = jit_insn_opnd_first_use(insn);
362+
unsigned i;
364363
JitReg *regp;
364+
unsigned first_use = jit_insn_opnd_first_use(insn);
365+
JitReg reg_defined;
365366

366367
/* check if there is the definition of an vr before its references */
367-
JIT_REG_VEC_FOREACH_USE(regvec, j, regp, first_use)
368+
JIT_REG_VEC_FOREACH(regvec, i, regp)
368369
{
369370
VirtualReg *vr = NULL;
370371

371372
if (!is_alloc_candidate(rc->cc, *regp))
372373
continue;
373374

375+
/*a strong assumption that there is only on defined reg*/
376+
if (i < first_use) {
377+
reg_defined = *regp;
378+
continue;
379+
}
380+
381+
/**
382+
* both definition and references are in one instruction,
383+
* like MOV i3,i3
384+
**/
385+
if (reg_defined == *regp)
386+
continue;
387+
374388
vr = rc_get_vr(rc, *regp);
375389
bh_assert(vr->distances);
376390
}

0 commit comments

Comments
 (0)