[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Nov 2 21:46:23 PST 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.72 -> 1.73
---
Log message:

Reject integer literals that are out of range for their type.


---
Diffs of the changes:  (+19 -1)

 DAGISelEmitter.cpp |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletion(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.72 llvm/utils/TableGen/DAGISelEmitter.cpp:1.73
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.72	Wed Nov  2 00:49:14 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Wed Nov  2 23:46:11 2005
@@ -482,10 +482,28 @@
 /// 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;
   }
   






More information about the llvm-commits mailing list