[X86] Remove special validation for INT immediate operand from AsmParser. Instead...
authorCraig Topper <craig.topper@gmail.com>
Sun, 11 Oct 2015 18:27:24 +0000 (18:27 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 11 Oct 2015 18:27:24 +0000 (18:27 +0000)
This also fixes a bug where negative immediates below -128 were not being reported as errors.

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

lib/Target/X86/AsmParser/X86AsmParser.cpp
lib/Target/X86/X86InstrSystem.td
test/CodeGen/X86/int-intrinsic.ll
test/MC/X86/validate-inst-att.s
test/MC/X86/validate-inst-intel.s

index 01c92c6222402fa2adbfab20ae988782d4d38472..c6bb895cdaf138f1fab7347b9e435d7283deaf8e 100644 (file)
@@ -718,7 +718,6 @@ private:
   bool ParseDirectiveWord(unsigned Size, SMLoc L);
   bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
 
-  bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
   bool processInstruction(MCInst &Inst, const OperandVector &Ops);
 
   /// Wrapper around MCStreamer::EmitInstruction(). Possibly adds
@@ -2401,22 +2400,6 @@ static bool convert64i32to64ri8(MCInst &Inst, unsigned Opcode,
   return convertToSExti8(Inst, Opcode, X86::RAX, isCmp);
 }
 
-bool X86AsmParser::validateInstruction(MCInst &Inst, const OperandVector &Ops) {
-  switch (Inst.getOpcode()) {
-  default: return true;
-  case X86::INT:
-    X86Operand &Op = static_cast<X86Operand &>(*Ops[1]);
-    assert(Op.isImm() && "expected immediate");
-    int64_t Res;
-    if (!Op.getImm()->evaluateAsAbsolute(Res) || Res > 255) {
-      Error(Op.getStartLoc(), "interrupt vector must be in range [0-255]");
-      return false;
-    }
-    return true;
-  }
-  llvm_unreachable("handle the instruction appropriately");
-}
-
 bool X86AsmParser::processInstruction(MCInst &Inst, const OperandVector &Ops) {
   switch (Inst.getOpcode()) {
   default: return false;
@@ -2579,9 +2562,6 @@ bool X86AsmParser::MatchAndEmitATTInstruction(SMLoc IDLoc, unsigned &Opcode,
                                isParsingIntelSyntax())) {
   default: llvm_unreachable("Unexpected match result!");
   case Match_Success:
-    if (!validateInstruction(Inst, Operands))
-      return true;
-
     // Some instructions need post-processing to, for example, tweak which
     // encoding is selected. Loop on it while changes happen so the
     // individual transformations can chain off each other.
@@ -2825,9 +2805,6 @@ bool X86AsmParser::MatchAndEmitIntelInstruction(SMLoc IDLoc, unsigned &Opcode,
   unsigned NumSuccessfulMatches =
       std::count(std::begin(Match), std::end(Match), Match_Success);
   if (NumSuccessfulMatches == 1) {
-    if (!validateInstruction(Inst, Operands))
-      return true;
-
     // Some instructions need post-processing to, for example, tweak which
     // encoding is selected. Loop on it while changes happen so the individual
     // transformations can chain off each other.
index 0350566f8b9b6048e23a0cd22008d828d2336cfe..917ae32382a8df47a23e6f64aefd54b7d4981ed4 100644 (file)
@@ -44,7 +44,7 @@ def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3",
 
 let SchedRW = [WriteSystem] in {
 
-def INT : Ii8<0xcd, RawFrm, (outs), (ins i8imm:$trap), "int\t$trap",
+def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap",
               [(int_x86_int imm:$trap)], IIC_INT>;
 
 
index 45a9b0f15c674d1a57c441452568533070600cd3..b253e6c5f3b02bfac411bc092005afe2ef93ae2f 100644 (file)
@@ -11,7 +11,7 @@ bb.entry:
   ret void
 }
 
-; CHECK: int   $-128
+; CHECK: int   $128
 ; CHECK: ret
 define void @primitive_int128 () {
 bb.entry:
index dec8bfdf66002c38651b951b0a09ef21378707e8..61d5813613a4d5c68ff5b624a366b45358796105 100644 (file)
@@ -2,6 +2,11 @@
 
        .text
        int $65535
-# CHECK: error: interrupt vector must be in range [0-255]
+# CHECK: error: invalid operand for instruction
 # CHECK:       int $65535
+# CHECK:            ^
+
+       int $-129
+# CHECK: error: invalid operand for instruction
+# CHECK:       int $-129
 # CHECK:            ^
index 9a7d122ca781cb07db6555d545ba348bdf4de96a..466b906fee731eaf4af637f6a475402c037717c7 100644 (file)
@@ -3,7 +3,13 @@
 
        .text
        int 65535
-# CHECK: error: interrupt vector must be in range [0-255]
+# CHECK: error: invalid operand for instruction
 # CHECK:       int 65535
+# CHECK:            ^
+
+       .text
+       int -129
+# CHECK: error: invalid operand for instruction
+# CHECK:       int -129
 # CHECK:            ^