From b1cfd2730e42d8a0b8d5f76f0c05dac948925dec Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Sun, 19 Mar 2017 20:15:24 +0000 Subject: [PATCH] lj_asm_x86.h: Fix CNEWI for constant pointers The JITed code for CNEWI did not handle the case where a pointer is initialized from a constant. This problem was inherited from LuaJIT v2.1 (LJ_GC64 only) and this fix has been reported to them too. --- src/lj_asm_x86.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index 8cd0a6526e..1fcad17713 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -1373,8 +1373,8 @@ static void asm_cnew(ASMState *as, IRIns *ir) Reg r64 = sz == 8 ? REX_64 : 0; if (irref_isk(ir->op2)) { IRIns *irk = IR(ir->op2); - uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 : - (uint64_t)(uint32_t)irk->i; + uint64_t k = (irk->o == IR_KINT64 || irk->o == IR_KPTR || irk->o == IR_KPTR) + ? ir_k64(irk)->u64 : (uint64_t)(uint32_t)irk->i; if (sz == 4 || checki32((int64_t)k)) { emit_i32(as, (int32_t)k); emit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata));