Skip to content

Commit 96fa546

Browse files
authored
Add a sanitizer to check if there is a definition of vreg before its (#1224)
1 parent 0ab070a commit 96fa546

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

core/iwasm/fast-jit/jit_regalloc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "jit_utils.h"
77
#include "jit_compiler.h"
88

9+
#if BH_DEBUG != 0
10+
#define VREG_DEF_SANITIZER
11+
#endif
12+
913
/**
1014
* A uint16 stack for storing distances of occurrences of virtual
1115
* registers.
@@ -350,6 +354,29 @@ is_alloc_candidate(JitCompContext *cc, JitReg reg)
350354
&& (!jit_cc_is_hreg(cc, reg) || !jit_cc_is_hreg_fixed(cc, reg)));
351355
}
352356

357+
#ifdef VREG_DEF_SANITIZER
358+
static void
359+
check_vreg_definition(RegallocContext *rc, JitInsn *insn)
360+
{
361+
unsigned j;
362+
JitRegVec regvec = jit_insn_opnd_regs(insn);
363+
unsigned first_use = jit_insn_opnd_first_use(insn);
364+
JitReg *regp;
365+
366+
/* check if there is the definition of an vr before its references */
367+
JIT_REG_VEC_FOREACH_USE(regvec, j, regp, first_use)
368+
{
369+
VirtualReg *vr = NULL;
370+
371+
if (!is_alloc_candidate(rc->cc, *regp))
372+
continue;
373+
374+
vr = rc_get_vr(rc, *regp);
375+
bh_assert(vr->distances);
376+
}
377+
}
378+
#endif
379+
353380
/**
354381
* Collect distances from the beginning of basic block of all occurrences of
355382
* each virtual register.
@@ -371,6 +398,10 @@ collect_distances(RegallocContext *rc, JitBasicBlock *basic_block)
371398
unsigned i;
372399
JitReg *regp;
373400

401+
#ifdef VREG_DEF_SANITIZER
402+
check_vreg_definition(rc, insn);
403+
#endif
404+
374405
/* NOTE: the distance may be pushed more than once if the
375406
virtual register occurs multiple times in the
376407
instruction. */

0 commit comments

Comments
 (0)