Tighten up error checking in parser, disallowing instructions that f.e.,
authorChris Lattner <sabre@nondot.org>
Tue, 10 Sep 2002 19:57:26 +0000 (19:57 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 10 Sep 2002 19:57:26 +0000 (19:57 +0000)
add pointers together.

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

lib/AsmParser/llvmAsmParser.y

index d40a8706d446ff982e2e8e249c7ab93ea9546b41..58de57aaf79c8a05738ea21029fbaf64b8c8bda8 100644 (file)
@@ -686,6 +686,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
 
 // Binary Operators 
 %type  <BinaryOpVal> BinaryOps  // all the binary operators
+%type  <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
 %token <BinaryOpVal> ADD SUB MUL DIV REM AND OR XOR
 %token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE  // Binary Comarators
 
@@ -720,8 +721,11 @@ EINT64VAL : EUINT64VAL {
 // Operations that are notably excluded from this list include: 
 // RET, BR, & SWITCH because they end basic blocks and are treated specially.
 //
-BinaryOps : ADD | SUB | MUL | DIV | REM | AND | OR | XOR;
-BinaryOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
+ArithmeticOps: ADD | SUB | MUL | DIV | REM;
+LogicalOps   : AND | OR | XOR;
+SetCondOps   : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
+BinaryOps : ArithmeticOps | LogicalOps | SetCondOps;
+
 ShiftOps  : SHL | SHR;
 
 // These are some types that allow classification if we only want a particular 
@@ -1507,7 +1511,23 @@ ValueRefList : ResolvedVal {    // Used for call statements, and memory insts...
 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
 ValueRefListE : ValueRefList | /*empty*/ { $$ = 0; };
 
-InstVal : BinaryOps Types ValueRef ',' ValueRef {
+InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
+    if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint())
+      ThrowException("Arithmetic operator requires integer or FP operands!");
+    $$ = BinaryOperator::create($1, getVal(*$2, $3), getVal(*$2, $5));
+    if ($$ == 0)
+      ThrowException("binary operator returned null!");
+    delete $2;
+  }
+  | LogicalOps Types ValueRef ',' ValueRef {
+    if (!(*$2)->isIntegral())
+      ThrowException("Logical operator requires integral operands!");
+    $$ = BinaryOperator::create($1, getVal(*$2, $3), getVal(*$2, $5));
+    if ($$ == 0)
+      ThrowException("binary operator returned null!");
+    delete $2;
+  }
+  | SetCondOps Types ValueRef ',' ValueRef {
     $$ = BinaryOperator::create($1, getVal(*$2, $3), getVal(*$2, $5));
     if ($$ == 0)
       ThrowException("binary operator returned null!");