Skip to content

Commit

Permalink
[LoongArch] Fix undefined behavior: left shift of negative value
Browse files Browse the repository at this point in the history
Fix undefined behavior in `decodeSImmOperand` where we were left shifting
a signed value.
  • Loading branch information
wangleiat committed Jan 11, 2023
1 parent ae6a5c1 commit f292d53
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -114,9 +114,9 @@ static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm,
int64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<N>(Imm) && "Invalid immediate");
// Sign-extend the number in the bottom <N> bits of Imm, then shift left <S>
// Shift left Imm <S> bits, then sign-extend the number in the bottom <N+S>
// bits.
Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm) << S));
Inst.addOperand(MCOperand::createImm(SignExtend64<N + S>(Imm << S)));
return MCDisassembler::Success;
}

Expand Down

0 comments on commit f292d53

Please sign in to comment.