Fixed the arm disassembly of invalid BFI instructions to not build a bad MCInst
[oota-llvm.git] / lib / Target / ARM / Disassembler / ARMDisassembler.cpp
index f00142de50dc2dbffe13ac2a8e514eae73ff32a1..5de50d592e762c6f6528c0cfc9fc6292aab4aa52 100644 (file)
@@ -1281,7 +1281,13 @@ static DecodeStatus DecodeBitfieldMaskOperand(MCInst &Inst, unsigned Val,
   unsigned lsb = fieldFromInstruction(Val, 0, 5);
 
   DecodeStatus S = MCDisassembler::Success;
-  if (lsb > msb) Check(S, MCDisassembler::SoftFail);
+  if (lsb > msb) {
+    Check(S, MCDisassembler::SoftFail);
+    // The check above will cause the warning for the "potentially undefined
+    // instruction encoding" but we can't build a bad MCOperand value here
+    // with a lsb > msb or else printing the MCInst will cause a crash.
+    lsb = msb;
+  }
 
   uint32_t msb_mask = 0xFFFFFFFF;
   if (msb != 31) msb_mask = (1U << (msb+1)) - 1;