diff options
author | Craig Topper <craig.topper@sifive.com> | 2025-03-31 21:49:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-31 21:49:07 -0700 |
commit | e3adf6bbfc72de043cffb3144079a9eb85e9ca40 (patch) | |
tree | 0abacb4ae34695f744afc58d7a38bfc20aa786b2 /llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp | |
parent | b3c7d5951673cf45150f80744a89866c6646eb71 (diff) | |
download | llvm-e3adf6bbfc72de043cffb3144079a9eb85e9ca40.zip llvm-e3adf6bbfc72de043cffb3144079a9eb85e9ca40.tar.gz llvm-e3adf6bbfc72de043cffb3144079a9eb85e9ca40.tar.bz2 |
[RISCV] Use decodeCLUIImmOperand when disassembling C_LUI_HINT. (#133789)
This correctly rejects imm==0 and prints 1048575 instead of -1.
I've modified the test to only have each hex pattern once with different
check lines before it. This ensures we don't have more invalid messages
printed than we're checking for.
Diffstat (limited to 'llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp')
-rw-r--r-- | llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp index fe1ab65..5f26800 100644 --- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -484,9 +484,13 @@ static DecodeStatus decodeRVCInstrRdRs1ImmZero(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder); -static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn, - uint64_t Address, - const MCDisassembler *Decoder); +static DecodeStatus decodeRVCInstrRdSImm6(MCInst &Inst, uint32_t Insn, + uint64_t Address, + const MCDisassembler *Decoder); + +static DecodeStatus decodeRVCInstrRdCLUIImm(MCInst &Inst, uint32_t Insn, + uint64_t Address, + const MCDisassembler *Decoder); static DecodeStatus decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn, @@ -544,18 +548,27 @@ static DecodeStatus decodeCSSPushPopchk(MCInst &Inst, uint32_t Insn, return MCDisassembler::Success; } -static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn, - uint64_t Address, - const MCDisassembler *Decoder) { +static DecodeStatus decodeRVCInstrRdSImm6(MCInst &Inst, uint32_t Insn, + uint64_t Address, + const MCDisassembler *Decoder) { Inst.addOperand(MCOperand::createReg(RISCV::X0)); - uint32_t SImm6 = + uint32_t Imm = fieldFromInstruction(Insn, 12, 1) << 5 | fieldFromInstruction(Insn, 2, 5); [[maybe_unused]] DecodeStatus Result = - decodeSImmOperand<6>(Inst, SImm6, Address, Decoder); + decodeSImmOperand<6>(Inst, Imm, Address, Decoder); assert(Result == MCDisassembler::Success && "Invalid immediate"); return MCDisassembler::Success; } +static DecodeStatus decodeRVCInstrRdCLUIImm(MCInst &Inst, uint32_t Insn, + uint64_t Address, + const MCDisassembler *Decoder) { + Inst.addOperand(MCOperand::createReg(RISCV::X0)); + uint32_t Imm = + fieldFromInstruction(Insn, 12, 1) << 5 | fieldFromInstruction(Insn, 2, 5); + return decodeCLUIImmOperand(Inst, Imm, Address, Decoder); +} + static DecodeStatus decodeRVCInstrRdRs1UImmLog2XLenNonZero(MCInst &Inst, uint32_t Insn, uint64_t Address, |