Fix bug: TableGen/BitsInitOverflow.td
authorChris Lattner <sabre@nondot.org>
Sun, 3 Aug 2003 18:24:34 +0000 (18:24 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 3 Aug 2003 18:24:34 +0000 (18:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7524 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/Record.cpp
utils/TableGen/Record.cpp

index ef7d9a044ae66e1ffad1448d40d3604ac9328744..204929e0244c04d4e67df5acb171bdf01dc641d7 100644 (file)
@@ -53,10 +53,19 @@ Init *BitsRecTy::convertValue(BitInit *UI) {
 //
 Init *BitsRecTy::convertValue(IntInit *II) {
   int Value = II->getValue();
+  // Make sure this bitfield is large enough to hold the integer value...
+  if (Value >= 0) {
+    if (Value & ~((1 << Size)-1))
+      return 0;
+  } else {
+    if ((Value >> Size) != -1 || ((Value & (1 << Size-1)) == 0))
+      return 0;
+  }
 
   BitsInit *Ret = new BitsInit(Size);
   for (unsigned i = 0; i != Size; ++i)
     Ret->setBit(i, new BitInit(Value & (1 << i)));
+
   return Ret;
 }
 
index ef7d9a044ae66e1ffad1448d40d3604ac9328744..204929e0244c04d4e67df5acb171bdf01dc641d7 100644 (file)
@@ -53,10 +53,19 @@ Init *BitsRecTy::convertValue(BitInit *UI) {
 //
 Init *BitsRecTy::convertValue(IntInit *II) {
   int Value = II->getValue();
+  // Make sure this bitfield is large enough to hold the integer value...
+  if (Value >= 0) {
+    if (Value & ~((1 << Size)-1))
+      return 0;
+  } else {
+    if ((Value >> Size) != -1 || ((Value & (1 << Size-1)) == 0))
+      return 0;
+  }
 
   BitsInit *Ret = new BitsInit(Size);
   for (unsigned i = 0; i != Size; ++i)
     Ret->setBit(i, new BitInit(Value & (1 << i)));
+
   return Ret;
 }