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().
This commit is contained in:
Cyan Ogilvie 2026-04-16 10:22:00 -03:00
parent d5ecb52a71
commit 690fb14015

View File

@ -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 */