Range checking for 16-bit immediates in ARM assembly.
authorJim Grosbach <grosbach@apple.com>
Wed, 13 Jul 2011 20:10:10 +0000 (20:10 +0000)
committerJim Grosbach <grosbach@apple.com>
Wed, 13 Jul 2011 20:10:10 +0000 (20:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135071 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstrInfo.td
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/basic-arm-instructions.s
test/MC/ARM/diagnostics.s

index 10410a54e665a63fac141afd81eeb353634b711a..7c0199dfeeeee1e5db82470a97d6f4398b974ada 100644 (file)
@@ -256,9 +256,12 @@ def lo16AllZero : PatLeaf<(i32 imm), [{
 }], hi16>;
 
 /// imm0_65535 - An immediate is in the range [0.65535].
+def Imm0_65535AsmOperand: AsmOperandClass { let Name = "Imm0_65535"; }
 def imm0_65535 : Operand<i32>, ImmLeaf<i32, [{
   return Imm >= 0 && Imm < 65536;
-}]>;
+}]> {
+  let ParserMatchClass = Imm0_65535AsmOperand;
+}
 
 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
index c72b206db9e359072e264d8a35a08b8e1e36b794..0ce4b4c128284cf83c69d628c438cd648d661be4 100644 (file)
@@ -386,6 +386,14 @@ public:
     int64_t Value = CE->getValue();
     return Value >= 0 && Value < 256;
   }
+  bool isImm0_65535() const {
+    if (Kind != Immediate)
+      return false;
+    const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
+    if (!CE) return false;
+    int64_t Value = CE->getValue();
+    return Value >= 0 && Value < 65536;
+  }
   bool isT2SOImm() const {
     if (Kind != Immediate)
       return false;
@@ -577,6 +585,11 @@ public:
     addExpr(Inst, getImm());
   }
 
+  void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
+    assert(N == 1 && "Invalid number of operands!");
+    addExpr(Inst, getImm());
+  }
+
   void addT2SOImmOperands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
     addExpr(Inst, getImm());
index 62339f7e597ff0f65b59716875858974555d97f9..f17fc66e1a057960a5abc0c2d4624304971a03df 100644 (file)
@@ -316,6 +316,5 @@ _func:
   bkpt #10
   bkpt #65535
 
-@ CHECK: bkpt  #10                     @ encoding: [0x7a,0x00,0x20,0xe1]
-@ CHECK: bkpt  #65535                  @ encoding: [0x7f,0xff,0x2f,0xe1]
-
+@ CHECK: bkpt  #10                      @ encoding: [0x7a,0x00,0x20,0xe1]
+@ CHECK: bkpt  #65535                   @ encoding: [0x7f,0xff,0x2f,0xe1]
index dab84c1df10727cfa86916d501f0aa34eba72b02..bf8f1259e9f8a456946bd45a0e6c63f0da3863c1 100644 (file)
@@ -40,4 +40,9 @@
 @ CHECK-ERRORS:                              ^
 @ CHECK-ERRORS: error: immediate shift value out of range
 @ CHECK-ERRORS:         adc r4, r5, r6, ror #32
-@ CHECK-ERRORS:                              ^
+
+
+        @ Out of range 16-bit immediate on BKPT
+        bkpt #65536
+
+@ CHECK-ERRORS: error: invalid operand for instruction