[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240381 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/Disassembler/MipsDisassembler.cpp

index c8629b5d7bd2a27f573e3aebc71df4c8003fae49..4a17d518e85f5f1ce86879a9a7584ebb79a35d27 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;
 }