[llvm-commits] [llvm] r61684 - in /llvm/trunk/lib/AsmParser: LLParser.cpp LLParser.h

Chris Lattner sabre at nondot.org
Mon Jan 5 00:24:46 PST 2009


Author: lattner
Date: Mon Jan  5 02:24:46 2009
New Revision: 61684

URL: http://llvm.org/viewvc/llvm-project?rev=61684&view=rev
Log:
Fix PR3281:crash08.ll with this diagnostic:
llvm-as: crash08.ll:3:15: invalid operand type for instruction
  "qp" = sdiv fp128 0x1, %30
              ^


Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/AsmParser/LLParser.h

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=61684&r1=61683&r2=61684&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jan  5 02:24:46 2009
@@ -2279,13 +2279,14 @@
   // Binary Operators.
   case lltok::kw_add:
   case lltok::kw_sub:
-  case lltok::kw_mul:
+  case lltok::kw_mul:    return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 0);
+      
   case lltok::kw_udiv:
   case lltok::kw_sdiv:
-  case lltok::kw_fdiv:
   case lltok::kw_urem:
-  case lltok::kw_srem:
-  case lltok::kw_frem:   return ParseArithmetic(Inst, PFS, Lex.getUIntVal());
+  case lltok::kw_srem:   return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 1);
+  case lltok::kw_fdiv:
+  case lltok::kw_frem:   return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 2);
   case lltok::kw_shl:
   case lltok::kw_lshr:
   case lltok::kw_ashr:
@@ -2619,18 +2620,31 @@
 //===----------------------------------------------------------------------===//
 
 /// ParseArithmetic
-///  ::= ArithmeticOps TypeAndValue ',' Value {
+///  ::= ArithmeticOps TypeAndValue ',' Value
+///
+/// If OperandType is 0, then any FP or integer operand is allowed.  If it is 1,
+/// then any integer operand is allowed, if it is 2, any fp operand is allowed.
 bool LLParser::ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
-                               unsigned Opc) {
+                               unsigned Opc, unsigned OperandType) {
   LocTy Loc; Value *LHS, *RHS;
   if (ParseTypeAndValue(LHS, Loc, PFS) ||
       ParseToken(lltok::comma, "expected ',' in arithmetic operation") ||
       ParseValue(LHS->getType(), RHS, PFS))
     return true;
 
-  if (!isa<IntegerType>(LHS->getType()) && !LHS->getType()->isFloatingPoint() &&
-      !isa<VectorType>(LHS->getType()))
-    return Error(Loc, "instruction requires integer, fp, or vector operands");
+  bool Valid;
+  switch (OperandType) {
+  default: assert(0 && "Unknown operand type!");
+  case 0: // int or FP.
+    Valid = LHS->getType()->isIntOrIntVector() ||
+            LHS->getType()->isFPOrFPVector();
+    break;
+  case 1: Valid = LHS->getType()->isIntOrIntVector(); break;
+  case 2: Valid = LHS->getType()->isFPOrFPVector(); break;
+  }
+  
+  if (!Valid)
+    return Error(Loc, "invalid operand type for instruction");
   
   Inst = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS);
   return false;

Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=61684&r1=61683&r2=61684&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Mon Jan  5 02:24:46 2009
@@ -247,7 +247,8 @@
     bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
     bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
 
-    bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
+    bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
+                         unsigned OperandType);
     bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
     bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
     bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc);





More information about the llvm-commits mailing list