[PATCH] D24814: Fix IntegerType::MAX_INT_BITS value

Andrey Bokhanko via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 14:47:53 PDT 2016


andreybokhanko created this revision.
andreybokhanko added reviewers: rnk, majnemer.
andreybokhanko added a subscriber: llvm-commits.

IntegerType::MAX_INT_BITS is apparently not in sync with Type::SubclassData size. This patch fixes this.

Not sure it would be better to introduce a #define or something in Type.h with SubclassData's size and use it in both places. I haven't seen a precedent elsewhere in llvm, so simply added a comment.

https://reviews.llvm.org/D24814

Files:
  include/llvm/IR/DerivedTypes.h
  include/llvm/IR/Type.h
  test/Assembler/invalid-inttype.ll
  test/Assembler/max-inttype.ll

Index: test/Assembler/invalid-inttype.ll
===================================================================
--- test/Assembler/invalid-inttype.ll
+++ test/Assembler/invalid-inttype.ll
@@ -0,0 +1,5 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; i16777216 is the smallest integer type that can't be represented in LLVM IR
+ at i2 = common global i16777216 0, align 4
+; CHECK: expected type
Index: test/Assembler/max-inttype.ll
===================================================================
--- test/Assembler/max-inttype.ll
+++ test/Assembler/max-inttype.ll
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s | llvm-dis
+
+; i16777215 is the maximum integer type represented in LLVM IR
+ at i2 = common global i16777215 0, align 4
Index: include/llvm/IR/Type.h
===================================================================
--- include/llvm/IR/Type.h
+++ include/llvm/IR/Type.h
@@ -81,6 +81,8 @@
 
   TypeID   ID : 8;            // The current base type of this type.
   unsigned SubclassData : 24; // Space for subclasses to store data.
+                              // Note that this should be synchronized with
+                              // MAX_INT_BITS value in IntegerType class.
 
 protected:
   friend class LLVMContextImpl;
Index: include/llvm/IR/DerivedTypes.h
===================================================================
--- include/llvm/IR/DerivedTypes.h
+++ include/llvm/IR/DerivedTypes.h
@@ -46,9 +46,10 @@
   /// This enum is just used to hold constants we need for IntegerType.
   enum {
     MIN_INT_BITS = 1,        ///< Minimum number of bits that can be specified
-    MAX_INT_BITS = (1<<23)-1 ///< Maximum number of bits that can be specified
+    MAX_INT_BITS = (1<<24)-1 ///< Maximum number of bits that can be specified
       ///< Note that bit width is stored in the Type classes SubclassData field
-      ///< which has 23 bits. This yields a maximum bit width of 8,388,607 bits.
+      ///< which has 24 bits. This yields a maximum bit width of 16,777,215
+      ///< bits.
   };
 
   /// This static method is the primary way of constructing an IntegerType.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24814.72110.patch
Type: text/x-patch
Size: 2094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160921/85a2e210/attachment.bin>


More information about the llvm-commits mailing list