Fix issues reported by Coverity static analysis (#1974)

This commit is contained in:
Wenyong Huang
2023-02-22 11:10:21 +08:00
committed by GitHub
parent bb5629811f
commit 0fa0813a5a
5 changed files with 21 additions and 7 deletions

View File

@ -156,6 +156,7 @@ rc_get_vr(RegallocContext *rc, JitReg vreg)
unsigned no = jit_reg_no(vreg);
bh_assert(jit_reg_is_variable(vreg));
bh_assert(kind < JIT_REG_KIND_L32);
return &rc->vregs[kind][no];
}
@ -175,6 +176,7 @@ rc_get_hr(RegallocContext *rc, JitReg hreg)
unsigned no = jit_reg_no(hreg);
bh_assert(jit_reg_is_variable(hreg) && jit_cc_is_hreg(rc->cc, hreg));
bh_assert(kind < JIT_REG_KIND_L32);
return &rc->hregs[kind][no];
}
@ -208,7 +210,9 @@ static unsigned
get_reg_stride(JitReg reg)
{
static const uint8 strides[] = { 0, 1, 2, 1, 2, 2, 4, 8, 0 };
return strides[jit_reg_kind(reg)];
uint32 kind = jit_reg_kind(reg);
bh_assert(kind <= JIT_REG_KIND_L32);
return strides[kind];
}
/**
@ -582,13 +586,17 @@ static JitReg
allocate_hreg(RegallocContext *rc, JitReg vreg, JitInsn *insn, int distance)
{
const int kind = jit_reg_kind(vreg);
const HardReg *hregs = rc->hregs[kind];
const unsigned hreg_num = jit_cc_hreg_num(rc->cc, kind);
const HardReg *hregs;
unsigned hreg_num;
JitReg hreg, vreg_to_reload = 0;
int min_distance = distance, vr_distance;
VirtualReg *vr = rc_get_vr(rc, vreg);
unsigned i;
bh_assert(kind < JIT_REG_KIND_L32);
hregs = rc->hregs[kind];
hreg_num = jit_cc_hreg_num(rc->cc, kind);
if (hreg_num == 0)
/* Unsupported hard register kind. */
{