fix(asm): refuse the riscv64 width moves across register banks

Assisted-by: GLM 5.3
This commit is contained in:
petrbalvin committed 2026-10-07 13:51:02 +02:00
1 parent f2892e4f59
commit 9d50212a71
1 file changed
+12
+12
View File
@@ -2095,17 +2095,29 @@ func encodeRISCVMov(instr *ast.Instr, fi riscvFrameInfo, relocs *[]Reloc, lits *
// ADDIW $0, rs, rd; the two-operand-only form never has
// rd == rs1 in real sources, and the toolchain's C.ADDIW
// forbids a zero immediate, so the word stays uncompressed.
if srcF || dstF {
return nil, fmt.Errorf("%s: expected integer register in rd position", mnem)
}
return wordLE(riscvIType(riscvEnc{0x1B, 0x0, 0x00}, rd, rs1, 0)), nil
case "MOVBU":
// ANDI $255, rs, rd; 255 never fits C.ANDI's six signed bits.
if srcF || dstF {
return nil, fmt.Errorf("%s: expected integer register in rd position", mnem)
}
return wordLE(riscvIType(riscvEnc{0x13, 0x7, 0x00}, rd, rs1, 0xFF)), nil
case "MOVB", "MOVH":
if srcF || dstF {
return nil, fmt.Errorf("%s: expected integer register in rd position", mnem)
}
shamt := 56
if mnem == "MOVH" {
shamt = 48
}
return riscvExtendBytes(rd, rs1, shamt, true), nil
case "MOVHU", "MOVWU":
if srcF || dstF {
return nil, fmt.Errorf("%s: expected integer register in rd position", mnem)
}
shamt := 48
if mnem == "MOVWU" {
shamt = 32