OSDN Git Service

[ARM] Fix integer UB in MVE load/store immediate handling.
authorSimon Tatham <simon.tatham@arm.com>
Fri, 28 Jun 2019 09:28:39 +0000 (09:28 +0000)
committerSimon Tatham <simon.tatham@arm.com>
Fri, 28 Jun 2019 09:28:39 +0000 (09:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364635 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/Disassembler/ARMDisassembler.cpp
lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp

index 9fb2fa6..673691e 100644 (file)
@@ -4182,7 +4182,7 @@ static DecodeStatus DecodeT2Imm7(MCInst &Inst, unsigned Val,
   else if (!(Val & 0x80))
     imm *= -1;
   if (imm != INT32_MIN)
-    imm <<= shift;
+    imm *= (1U << shift);
   Inst.addOperand(MCOperand::createImm(imm));
 
   return MCDisassembler::Success;
@@ -4448,7 +4448,7 @@ static DecodeStatus DecodeMveAddrModeQ(MCInst &Inst, unsigned Insn,
       imm *= -1;
   }
   if (imm != INT32_MIN)
-    imm <<= shift;
+    imm *= (1U << shift);
   Inst.addOperand(MCOperand::createImm(imm));
 
   return S;
index c506f26..dca6fe3 100644 (file)
@@ -1621,12 +1621,15 @@ getT2AddrModeImmOpValue(const MCInst &MI, unsigned OpNum,
   // If the immediate is B bits long, we need B+1 bits in order
   // to represent the (inverse of the) sign bit.
   Value <<= (Bits + 1);
-  int32_t tmp = (int32_t)MO2.getImm() >> Shift;
-  if (tmp < 0)
+  int32_t tmp = (int32_t)MO2.getImm();
+  if (tmp == INT32_MIN) { // represents subtracting zero rather than adding it
+    tmp = 0;
+  } else if (tmp < 0) {
     tmp = abs(tmp);
-  else
+  } else {
     Value |= (1U << Bits); // Set the ADD bit
-  Value |= tmp & ((1U << Bits) - 1);
+  }
+  Value |= (tmp >> Shift) & ((1U << Bits) - 1);
   return Value;
 }