Better error handling of invalid IT mask '0000', instead of just asserting.
authorJohnny Chen <johnny.chen@apple.com>
Mon, 19 Apr 2010 23:02:58 +0000 (23:02 +0000)
committerJohnny Chen <johnny.chen@apple.com>
Mon, 19 Apr 2010 23:02:58 +0000 (23:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101827 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/Disassembler/ARMDisassembler.cpp
lib/Target/ARM/Disassembler/ARMDisassembler.h
lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp

index 0e27e16f9417fc20555ba5fbde8b3c26e8745570..1c9d95fb08a22ab4dc2bd1bc9c885e0925213c4f 100644 (file)
@@ -508,17 +508,23 @@ bool ThumbDisassembler::getInstruction(MCInst &MI,
 }
 
 // A8.6.50
+// Valid return values are {1, 2, 3, 4}, with 0 signifying an error condition.
 static unsigned short CountITSize(unsigned ITMask) {
   // First count the trailing zeros of the IT mask.
   unsigned TZ = CountTrailingZeros_32(ITMask);
-  assert(TZ <= 3 && "Encoding error");
+  if (TZ > 3) {
+    DEBUG(errs() << "Encoding error of IT mask");
+    return 0;
+  }
   return (4 - TZ);
 }
 
-/// Init ITState.
-void Session::InitIT(unsigned short bits7_0) {
+/// Init ITState.  Note that at least one bit is always 1 in mask.
+bool Session::InitIT(unsigned short bits7_0) {
   ITCounter = CountITSize(slice(bits7_0, 3, 0));
   ITState = bits7_0;
+  // Only need to check for > 0.
+  return ITCounter > 0;
 }
 
 /// Update ITState if necessary.
index e418b2ba51eff46faa2c928842df6d72f7d21aed..0a74a3866eedc660c32070e26db55686b9876d6c 100644 (file)
@@ -60,7 +60,7 @@ public:
   Session() : ITCounter(0), ITState(0) {}
   ~Session() {}
   /// InitIT - Initializes ITCounter/ITState.
-  void InitIT(unsigned short bits7_0);
+  bool InitIT(unsigned short bits7_0);
   /// UpdateIT - Updates ITCounter/ITState as IT Block progresses.
   void UpdateIT();
 
index c261948d9093df495442c6ee6526c09b4c39b29d..6e76200b35e4cd4377209b8c624040bd2dbea07a 100644 (file)
@@ -3282,7 +3282,7 @@ bool ARMBasicMCBuilder::RunBuildAfterHook(bool Status, MCInst &MI,
   if (!SP) return Status;
 
   if (Opcode == ARM::t2IT)
-    SP->InitIT(slice(insn, 7, 0));
+    Status = SP->InitIT(slice(insn, 7, 0)) ? Status : false;
   else if (InITBlock())
     SP->UpdateIT();