diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp index 66970ed37f27247..54f1a3899c4957b 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp @@ -77,7 +77,7 @@ class RISCVMCCodeEmitter : public MCCodeEmitter { /// Return binary encoding of operand. If the machine operand requires /// relocation, record the relocation and return zero. - unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, + uint64_t getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl &Fixups, const MCSubtargetInfo &STI) const; @@ -375,7 +375,7 @@ void RISCVMCCodeEmitter::encodeInstruction(const MCInst &MI, ++MCNumEmitted; // Keep track of the # of mi's emitted. } -unsigned +uint64_t RISCVMCCodeEmitter::getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl &Fixups, const MCSubtargetInfo &STI) const { @@ -384,7 +384,7 @@ RISCVMCCodeEmitter::getMachineOpValue(const MCInst &MI, const MCOperand &MO, return Ctx.getRegisterInfo()->getEncodingValue(MO.getReg()); if (MO.isImm()) - return static_cast(MO.getImm()); + return MO.getImm(); llvm_unreachable("Unhandled expression!"); return 0; diff --git a/llvm/test/MC/RISCV/insn.s b/llvm/test/MC/RISCV/insn.s index e32fec25bb16b43..d24f4fe8b36374c 100644 --- a/llvm/test/MC/RISCV/insn.s +++ b/llvm/test/MC/RISCV/insn.s @@ -170,17 +170,40 @@ target: # CHECK-OBJ: .insn 6, 0x1f -# CHECK-ASM: .insn 0x4, 65503 -# CHECK-ASM: encoding: [0xdf,0xff,0x00,0x00] -# CHECK-OBJ: -.insn 0xffdf - # CHECK-ASM: .insn 0x8, 63 # CHECK-ASM: encoding: [0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00] # CHECK-OBJ: .insn 8, 0x3f +# CHECK-ASM: .insn 0x6, 281474976710623 +# CHECK-ASM: encoding: [0xdf,0xff,0xff,0xff,0xff,0xff] +# CHECK-OBJ: +.insn 0x6, 0xffffffffffdf + +# CHECK-ASM: .insn 0x8, -65 +# CHECK-ASM: encoding: [0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff] +# CHECK-OBJ: +.insn 0x8, 0xffffffffffffffbf + +odd_lengths: +# CHECK-ASM-LABEL: odd_lengths: +# CHECK-OBJ-LABEL: : + +## These deliberately disagree with the lengths objdump expects them to have, so +## keep them at the end so that the disassembled instruction stream is not out +## of sync with the encoded instruction stream. We don't check for `` +## as we could get any number of those, so instead check for the encoding +## halfwords. These might be split into odd 16-bit chunks, so each chunk is on +## one line. + +# CHECK-ASM: .insn 0x4, 65503 +# CHECK-ASM: encoding: [0xdf,0xff,0x00,0x00] +# CHECK-OBJ: ffdf +# CHECK-OBJ: 0000 +.insn 0xffdf + # CHECK-ASM: .insn 0x4, 65471 # CHECK-ASM: encoding: [0xbf,0xff,0x00,0x00] -# CHECK-OBJ: +# CHECK-OBJ: ffbf +# CHECK-OBJ: 0000 .insn 0xffbf