Check for unallocated instruction encodings when disassembling Thumb Branch instructi...
authorJohnny Chen <johnny.chen@apple.com>
Wed, 13 Apr 2011 21:35:49 +0000 (21:35 +0000)
committerJohnny Chen <johnny.chen@apple.com>
Wed, 13 Apr 2011 21:35:49 +0000 (21:35 +0000)
rdar://problem/9280470

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

lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp
test/MC/Disassembler/ARM/invalid-t2Bcc-thumb.txt [new file with mode: 0644]
test/MC/Disassembler/ARM/thumb-tests.txt

index dc04227420ba4f83f4c7beed89431f76f6de8a49..4ecb8be012df7b2521130f60960f1d0096878068 100644 (file)
@@ -3625,11 +3625,17 @@ bool ARMBasicMCBuilder::TryPredicateAndSBitModifier(MCInst& MI, unsigned Opcode,
         // like ARM.
         //
         // A8.6.16 B
-        if (Name == "t2Bcc")
-          MI.addOperand(MCOperand::CreateImm(CondCode(slice(insn, 25, 22))));
-        else if (Name == "tBcc")
-          MI.addOperand(MCOperand::CreateImm(CondCode(slice(insn, 11, 8))));
-        else
+        // Check for undefined encodings.
+        unsigned cond;
+        if (Name == "t2Bcc") {
+          if ((cond = slice(insn, 25, 22)) >= 14)
+            return false;
+          MI.addOperand(MCOperand::CreateImm(CondCode(cond)));
+        } else if (Name == "tBcc") {
+          if ((cond = slice(insn, 11, 8)) == 14)
+            return false;
+          MI.addOperand(MCOperand::CreateImm(CondCode(cond)));
+        } else
           MI.addOperand(MCOperand::CreateImm(ARMCC::AL));
       } else {
         // ARM instructions get their condition field from Inst{31-28}.
diff --git a/test/MC/Disassembler/ARM/invalid-t2Bcc-thumb.txt b/test/MC/Disassembler/ARM/invalid-t2Bcc-thumb.txt
new file mode 100644 (file)
index 0000000..d0bc51e
--- /dev/null
@@ -0,0 +1,11 @@
+# RUN: llvm-mc --disassemble %s -triple=thumb-apple-darwin9 |& grep {invalid instruction encoding}
+
+# Opcode=1894 Name=t2Bcc Format=ARM_FORMAT_THUMBFRM(25)
+#  31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0 
+# -------------------------------------------------------------------------------------------------
+# | 1: 1: 1: 1| 0: 1: 1: 1| 1: 0: 1: 0| 1: 1: 1: 1| 1: 0: 0: 0| 1: 0: 1: 1| 0: 1: 0: 0| 0: 1: 0: 0|
+# -------------------------------------------------------------------------------------------------
+# 
+# A8.6.16 B
+# if cond<3:1> == '111' then SEE "Related Encodings"
+0xaf 0xf7 0x44 0x8b
index 4151e0c40b9ad61548339a6bb888cd8d801f7222..04bde41af6210d93d29abd9674786c3e50ec7f63 100644 (file)
@@ -9,8 +9,8 @@
 # CHECK:       b       #30
 0x0f 0xe0
 
-# CHECK:       b.w     #-16
-0xff 0xf7 0xf8 0xaf
+# CHECK:       bgt.w   #-16
+0x3f 0xf7 0xf8 0xaf
 
 # CHECK:       bfi     r2, r10, #0, #1
 0x6a 0xf3 0x00 0x02