Skip to content

Commit bc37fea

Browse files
authored
[RISCV] Fix the disassembler's handling of C.LUI when imm=0 (#133450)
Fix for #133446. According to the RISC-V spec: "C.LUI is valid only when rd≠{x0,x2}, and when the immediate is not equal to zero. The code points with imm=0 are reserved". This change makes the disassembler consider code points with imm=0 as illegal. It introduces a test which exercises every C.LUI opcode including the illegal ones but excluding those assigned to C.ADDI16SP). Output for +c, +c +Zcmop, and +c +no-rvc-hints is checked.
1 parent d6d559c commit bc37fea

File tree

2 files changed

+2076
-2
lines changed

2 files changed

+2076
-2
lines changed

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,10 @@ static DecodeStatus decodeCLUIImmOperand(MCInst &Inst, uint32_t Imm,
453453
int64_t Address,
454454
const MCDisassembler *Decoder) {
455455
assert(isUInt<6>(Imm) && "Invalid immediate");
456-
if (Imm > 31) {
456+
if (Imm == 0)
457+
return MCDisassembler::Fail;
458+
if (Imm > 31)
457459
Imm = (SignExtend64<6>(Imm) & 0xfffff);
458-
}
459460
Inst.addOperand(MCOperand::createImm(Imm));
460461
return MCDisassembler::Success;
461462
}

0 commit comments

Comments
 (0)