From 690fb140151b05e63f6f51a9e0cd231c0d9fd44f Mon Sep 17 00:00:00 2001 From: Cyan Ogilvie Date: Thu, 16 Apr 2026 10:22:00 -0300 Subject: [PATCH] x86_64-gen: fix missing REX prefix for xor zero into r8-r15 load() used a raw o() call to emit xor-zero which lost bit 3 of the register number via REG_VALUE(): o(0xc031 + REG_VALUE(r) * 0x900); For r >= 8, this emitted the wrong instruction (e.g. xor %ebx,%ebx for TREG_R11 instead of xor %r11d,%r11d), clobbering the wrong register. Use orex() to emit the REX prefix, consistent with all adjacent branches in load(). --- x86_64-gen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x86_64-gen.c b/x86_64-gen.c index 2ca1ddec..af936b63 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -495,7 +495,8 @@ void load(int r, SValue *sv) orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */ gen_le32(sv->c.i); } else { - o(0xc031 + REG_VALUE(r) * 0x900); /* xor r, r */ + orex(0, r, r, 0x31); /* xor r, r */ + o(0xc0 + REG_VALUE(r) * 9); } } else { orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */