[llvm-commits] CVS: llvm/lib/VMCore/iOperators.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 10 14:58:05 PDT 2002


Changes in directory llvm/lib/VMCore:

iOperators.cpp updated: 1.18 -> 1.19

---
Log message:

Tighten up assertion checking for binary operators, not allowing invalid
instructions to _even be created_.


---
Diffs of the changes:

Index: llvm/lib/VMCore/iOperators.cpp
diff -u llvm/lib/VMCore/iOperators.cpp:1.18 llvm/lib/VMCore/iOperators.cpp:1.19
--- llvm/lib/VMCore/iOperators.cpp:1.18	Tue Sep 10 10:45:53 2002
+++ llvm/lib/VMCore/iOperators.cpp	Tue Sep 10 14:57:53 2002
@@ -17,11 +17,36 @@
                                const Type *Ty, const std::string &Name,
                                Instruction *InsertBefore)
   : Instruction(Ty, iType, Name, InsertBefore) {
+
   Operands.reserve(2);
   Operands.push_back(Use(S1, this));
   Operands.push_back(Use(S2, this));
-  assert(Operands[0] && Operands[1] && 
-         Operands[0]->getType() == Operands[1]->getType());
+  assert(S1 && S2 && S1->getType() == S2->getType());
+
+#ifndef NDEBUG
+  switch (iType) {
+  case Add: case Sub:
+  case Mul: case Div:
+  case Rem:
+    assert(Ty == S1->getType() &&
+           "Arithmetic operation should return same type as operands!");
+    assert((Ty->isInteger() || Ty->isFloatingPoint()) && 
+           "Tried to create an arithmetic operation on a non-arithmetic type!");
+    break;
+  case And: case Or:
+  case Xor:
+    assert(Ty == S1->getType() &&
+           "Logical operation should return same type as operands!");
+    assert(Ty->isIntegral() &&
+           "Tried to create an logical operation on a non-integral type!");
+    break;
+  case SetLT: case SetGT: case SetLE:
+  case SetGE: case SetEQ: case SetNE:
+    assert(Ty == Type::BoolTy && "Setcc must return bool!");
+  default:
+    break;
+  }
+#endif
 }
 
 





More information about the llvm-commits mailing list