From f292d53c70f96ca2beee448fb9bf2debaf0134a0 Mon Sep 17 00:00:00 2001 From: wanglei Date: Wed, 11 Jan 2023 21:16:38 +0800 Subject: [PATCH] [LoongArch] Fix undefined behavior: left shift of negative value Fix undefined behavior in `decodeSImmOperand` where we were left shifting a signed value. --- llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp b/llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp index beb757c..2335152 100644 --- a/llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp +++ b/llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp @@ -114,9 +114,9 @@ static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm, int64_t Address, const MCDisassembler *Decoder) { assert(isUInt(Imm) && "Invalid immediate"); - // Sign-extend the number in the bottom bits of Imm, then shift left + // Shift left Imm bits, then sign-extend the number in the bottom // bits. - Inst.addOperand(MCOperand::createImm(SignExtend64(Imm) << S)); + Inst.addOperand(MCOperand::createImm(SignExtend64(Imm << S))); return MCDisassembler::Success; } -- 2.7.4