[llvm] r240381 - [mips] Fix some UB by shifting before sign-extending

Justin Bogner mail at justinbogner.com
Tue Jun 23 00:28:58 PDT 2015


Author: bogner
Date: Tue Jun 23 02:28:57 2015
New Revision: 240381

URL: http://llvm.org/viewvc/llvm-project?rev=240381&view=rev
Log:
[mips] Fix some UB by shifting before sign-extending

Avoid shifting a negative value by sign-extending after the shift.

Fixes a couple of tests that were failing under ubsan.

Modified:
    llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp

Modified: llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp?rev=240381&r1=240380&r2=240381&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp Tue Jun 23 02:28:57 2015
@@ -1855,6 +1855,6 @@ static DecodeStatus DecodeMovePRegPair(M
 
 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;
 }





More information about the llvm-commits mailing list