Skip to content

Commit

Permalink
WASM_X64: Fix nullptr handling in base and index registers
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Dec 15, 2022
1 parent 924dc53 commit 356b3ca
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/libasr/codegen/x86_assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,19 @@ class X86Assembler {

void asm_mov_r64_m64(X64Reg r64, X64Reg *base, X64Reg *index,
uint8_t scale, int64_t disp) {
X86Reg r32 = X86Reg(r64 & 7), base32 = X86Reg(base & 7), index32 = X86Reg(index & 7);
m_code.push_back(m_al, rex(1, r64 >> 3, index32 >> 3, base32 >> 3));
X86Reg r32 = X86Reg(r64 & 7);
X86Reg* base32 = nullptr, *index32 = nullptr;
if (base) {
base32 = new X86Reg;
*base32 = X86Reg(*base & 7);
}
if (index) {
index32 = new X86Reg;
*index32 = X86Reg(*index & 7);
}
m_code.push_back(m_al, rex(1, r64 >> 3, (index32 ? (*index32 >> 3) : 0), (base32 ? (*base32 >> 3) : 0)));
m_code.push_back(m_al, 0x8b);
modrm_sib_disp(m_code, m_al,
modrm_sib_disp(m_code, m_al,
r32, base32, index32, scale, (int32_t)disp, true);
EMIT("mov " + r2s(r64) + ", " + m2s(base, index, scale, disp));
}
Expand All @@ -740,8 +749,17 @@ class X86Assembler {

void asm_mov_m64_r64(X64Reg *base, X64Reg *index,
uint8_t scale, int64_t disp, X64Reg r64) {
X86Reg r32 = X86Reg(r64 & 7), base32 = X86Reg(base & 7), index32 = X86Reg(index & 7);
m_code.push_back(m_al, rex(1, r64 >> 3, index32 >> 3, base32 >> 3));
X86Reg r32 = X86Reg(r64 & 7);
X86Reg* base32 = nullptr, *index32 = nullptr;
if (base) {
base32 = new X86Reg;
*base32 = X86Reg(*base & 7);
}
if (index) {
index32 = new X86Reg;
*index32 = X86Reg(*index & 7);
}
m_code.push_back(m_al, rex(1, r64 >> 3, (index32 ? (*index32 >> 3) : 0), (base32 ? (*base32 >> 3) : 0)));
m_code.push_back(m_al, 0x89);
modrm_sib_disp(m_code, m_al,
r32, base32, index32, scale, (int32_t)disp, true);
Expand Down

0 comments on commit 356b3ca

Please sign in to comment.