[mips] Fix some UB by shifting before sign-extending
authorJustin Bogner <mail@justinbogner.com>
Tue, 23 Jun 2015 07:28:57 +0000 (07:28 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 23 Jun 2015 07:28:57 +0000 (07:28 +0000)
Avoid shifting a negative value by sign-extending after the shift.

Fixes a couple of tests that were failing under ubsan.

llvm-svn: 240381

llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp

index c8629b5..4a17d51 100644 (file)
@@ -1855,6 +1855,6 @@ static DecodeStatus DecodeMovePRegPair(MCInst &Inst, unsigned Insn,
 
 static DecodeStatus DecodeSimm23Lsl2(MCInst &Inst, unsigned Insn,
                                      uint64_t Address, const void *Decoder) {
-  Inst.addOperand(MCOperand::createImm(SignExtend32<23>(Insn) << 2));
+  Inst.addOperand(MCOperand::createImm(SignExtend32<25>(Insn << 2)));
   return MCDisassembler::Success;
 }