aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-17 17:28:46 +0000
committerChris Lattner <sabre@nondot.org>2004-08-17 17:28:46 +0000
commit91b362bba9dbc9945262f0f74f00e1cf3a67c814 (patch)
tree8537d0cce26fea4102f7b96a79314fa546184f83
parentc6d2f15037643a3738d6bce1c09a9d3bdb3bdcaf (diff)
Check constant expression validity more strictly
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15883 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/Constants.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index bc274f0e32..69f1a78412 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1127,6 +1127,37 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
}
Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
+#ifndef NDEBUG
+ switch (Opcode) {
+ case Instruction::Add: case Instruction::Sub:
+ case Instruction::Mul: case Instruction::Div:
+ case Instruction::Rem:
+ assert(C1->getType() == C2->getType() && "Op types should be identical!");
+ assert((C1->getType()->isInteger() || C1->getType()->isFloatingPoint()) &&
+ "Tried to create an arithmetic operation on a non-arithmetic type!");
+ break;
+ case Instruction::And:
+ case Instruction::Or:
+ case Instruction::Xor:
+ assert(C1->getType() == C2->getType() && "Op types should be identical!");
+ assert(C1->getType()->isIntegral() &&
+ "Tried to create an logical operation on a non-integral type!");
+ break;
+ case Instruction::SetLT: case Instruction::SetGT: case Instruction::SetLE:
+ case Instruction::SetGE: case Instruction::SetEQ: case Instruction::SetNE:
+ assert(C1->getType() == C2->getType() && "Op types should be identical!");
+ break;
+ case Instruction::Shl:
+ case Instruction::Shr:
+ assert(C2->getType() == Type::UByteTy && "Shift should be by ubyte!");
+ assert(C1->getType()->isInteger() &&
+ "Tried to create a shift operation on a non-integer type!");
+ break;
+ default:
+ break;
+ }
+#endif
+
if (Instruction::isRelational(Opcode))
return getTy(Type::BoolTy, Opcode, C1, C2);
else