aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-03 05:46:11 +0000
committerChris Lattner <sabre@nondot.org>2005-11-03 05:46:11 +0000
commit465c737467dd70221a48fc7b9631f39283574d4e (patch)
tree50dffe473d894c3dadde0ba480c9cf1ce9150b3e
parent61bc60fc4f5f7a32817a1718d81b31416ec96e77 (diff)
Reject integer literals that are out of range for their type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24162 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--utils/TableGen/DAGISelEmitter.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp
index 29206ce3b4..5cc1f273af 100644
--- a/utils/TableGen/DAGISelEmitter.cpp
+++ b/utils/TableGen/DAGISelEmitter.cpp
@@ -482,10 +482,28 @@ static unsigned char getIntrinsicType(Record *R, bool NotRegisters,
/// exception.
bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
if (isLeaf()) {
- if (DefInit *DI = dynamic_cast<DefInit*>(getLeafValue()))
+ if (DefInit *DI = dynamic_cast<DefInit*>(getLeafValue())) {
// If it's a regclass or something else known, include the type.
return UpdateNodeType(getIntrinsicType(DI->getDef(), NotRegisters, TP),
TP);
+ } else if (IntInit *II = dynamic_cast<IntInit*>(getLeafValue())) {
+ // Int inits are always integers. :)
+ bool MadeChange = UpdateNodeType(MVT::isInt, TP);
+
+ if (hasTypeSet()) {
+ unsigned Size = MVT::getSizeInBits(getType());
+ // Make sure that the value is representable for this type.
+ if (Size < 32) {
+ int Val = (II->getValue() << (32-Size)) >> (32-Size);
+ if (Val != II->getValue())
+ TP.error("Sign-extended integer value '" + itostr(II->getValue()) +
+ "' is out of range for type 'MVT::" +
+ getEnumName(getType()) + "'!");
+ }
+ }
+
+ return MadeChange;
+ }
return false;
}