Add assertions.
authorChris Lattner <sabre@nondot.org>
Sun, 16 Jan 2005 02:23:22 +0000 (02:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Jan 2005 02:23:22 +0000 (02:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19596 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index d3d44a82e080316371842a65965d35f02ae61473..a8e383060f03bbfe9a5b576512b5cc1f374d6153 100644 (file)
@@ -543,6 +543,37 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
 
 SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
                                 SDOperand N1, SDOperand N2) {
+#ifndef NDEBUG
+  switch (Opcode) {
+  case ISD::AND:
+  case ISD::OR:
+  case ISD::XOR:
+  case ISD::UDIV:
+  case ISD::UREM:
+    assert(MVT::isInteger(VT) && "This operator does not apply to FP types!");
+    // fall through
+  case ISD::ADD:
+  case ISD::SUB:
+  case ISD::MUL:
+  case ISD::SDIV:
+  case ISD::SREM:
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
+    break;
+
+  case ISD::SHL:
+  case ISD::SRA:
+  case ISD::SRL:
+    assert(VT == N1.getValueType() &&
+           "Shift operators return type must be the same as their first arg");
+    assert(MVT::isInteger(VT) && MVT::isInteger(N2.getValueType()) &&
+           "Shifts only work on integers");
+    assert(VT >= MVT::i8 && "Shift amount cannot be a MVT::i1");
+    break;
+  default: break;
+  }
+#endif
+
   ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
   ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.Val);
   if (N1C) {