Make some assertions on constant expressions static.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Mar 2014 18:47:07 +0000 (18:47 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 15 Mar 2014 18:47:07 +0000 (18:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204011 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SparseMultiSet.h
include/llvm/ADT/SparseSet.h
include/llvm/Support/ArrayRecycler.h
include/llvm/Support/Recycler.h
lib/DebugInfo/DWARFDebugArangeSet.cpp
lib/IR/AsmWriter.cpp

index f80f6d7153fc3e4f57c47d5614da8ca601f203e3..797a898dcc307efbf3e498ef0556c69245aa3f3b 100644 (file)
@@ -76,6 +76,10 @@ template<typename ValueT,
          typename KeyFunctorT = llvm::identity<unsigned>,
          typename SparseT = uint8_t>
 class SparseMultiSet {
+  static_assert(std::numeric_limits<SparseT>::is_integer &&
+                !std::numeric_limits<SparseT>::is_signed,
+                "SparseT must be an unsigned integer type");
+
   /// The actual data that's stored, as a doubly-linked list implemented via
   /// indices into the DenseVector.  The doubly linked list is implemented
   /// circular in Prev indices, and INVALID-terminated in Next indices. This
@@ -344,9 +348,6 @@ public:
   ///
   iterator findIndex(unsigned Idx) {
     assert(Idx < Universe && "Key out of range");
-    assert(std::numeric_limits<SparseT>::is_integer &&
-           !std::numeric_limits<SparseT>::is_signed &&
-           "SparseT must be an unsigned integer type");
     const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
     for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; i += Stride) {
       const unsigned FoundIdx = sparseIndex(Dense[i]);
index ded48c5746a141dc93d49dd2fe20897c14ae8725..b46ccc937541fe6632b34197e2a62cf6f444e152 100644 (file)
@@ -118,6 +118,10 @@ template<typename ValueT,
          typename KeyFunctorT = llvm::identity<unsigned>,
          typename SparseT = uint8_t>
 class SparseSet {
+  static_assert(std::numeric_limits<SparseT>::is_integer &&
+                !std::numeric_limits<SparseT>::is_signed,
+                "SparseT must be an unsigned integer type");
+
   typedef typename KeyFunctorT::argument_type KeyT;
   typedef SmallVector<ValueT, 8> DenseT;
   DenseT Dense;
@@ -198,9 +202,6 @@ public:
   ///
   iterator findIndex(unsigned Idx) {
     assert(Idx < Universe && "Key out of range");
-    assert(std::numeric_limits<SparseT>::is_integer &&
-           !std::numeric_limits<SparseT>::is_signed &&
-           "SparseT must be an unsigned integer type");
     const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
     for (unsigned i = Sparse[Idx], e = size(); i < e; i += Stride) {
       const unsigned FoundIdx = ValIndexOf(Dense[i]);
index c7e0cba279e66d31d4736b532b96fba6602d3c07..19059b32cd3af7c05baeb11ee284985481a337b9 100644 (file)
@@ -35,6 +35,9 @@ class ArrayRecycler {
     FreeList *Next;
   };
 
+  static_assert(Align >= AlignOf<FreeList>::Alignment, "Object underaligned");
+  static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small");
+
   // Keep a free list for each array size.
   SmallVector<FreeList*, 8> Bucket;
 
@@ -53,8 +56,6 @@ class ArrayRecycler {
   // Add an entry to the free list at Bucket[Idx].
   void push(unsigned Idx, T *Ptr) {
     assert(Ptr && "Cannot recycle NULL pointer");
-    assert(sizeof(T) >= sizeof(FreeList) && "Objects are too small");
-    assert(Align >= AlignOf<FreeList>::Alignment && "Object underaligned");
     FreeList *Entry = reinterpret_cast<FreeList*>(Ptr);
     if (Idx >= Bucket.size())
       Bucket.resize(size_t(Idx) + 1);
index bcc561db2d5cbcf484ef52a0f01a84bfa981cb2f..129e8efd2b218b3eb87fb91f408d4e291fa64a8f 100644 (file)
@@ -100,10 +100,10 @@ public:
 
   template<class SubClass, class AllocatorType>
   SubClass *Allocate(AllocatorType &Allocator) {
-    assert(sizeof(SubClass) <= Size &&
-           "Recycler allocation size is less than object size!");
-    assert(AlignOf<SubClass>::Alignment <= Align &&
-           "Recycler allocation alignment is less than object alignment!");
+    static_assert(AlignOf<SubClass>::Alignment <= Align,
+                  "Recycler allocation alignment is less than object align!");
+    static_assert(sizeof(SubClass) <= Size,
+                  "Recycler allocation size is less than object size!");
     return !FreeList.empty() ?
            reinterpret_cast<SubClass *>(FreeList.remove(FreeList.begin())) :
            static_cast<SubClass *>(Allocator.Allocate(Size, Align));
index 8459cb1378930d21a621dc6ad63df522929bdf93..c0a33ceaf24324a0465579a93d153ec30594b884 100644 (file)
@@ -67,7 +67,9 @@ DWARFDebugArangeSet::extract(DataExtractor data, uint32_t *offset_ptr) {
 
     Descriptor arangeDescriptor;
 
-    assert(sizeof(arangeDescriptor.Address) == sizeof(arangeDescriptor.Length));
+    static_assert(sizeof(arangeDescriptor.Address) ==
+                      sizeof(arangeDescriptor.Length),
+                  "Different datatypes for addresses and sizes!");
     assert(sizeof(arangeDescriptor.Address) >= HeaderData.AddrSize);
 
     while (data.isValidOffset(*offset_ptr)) {
index 93a59a63c898cb92b49f6554df41f70f17f0a9fc..d4670e4bc6c21ae50f71cf50f59d5f4325ec01d8 100644 (file)
@@ -811,8 +811,8 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
       // output the string in hexadecimal format!  Note that loading and storing
       // floating point types changes the bits of NaNs on some hosts, notably
       // x86, so we must not use these types.
-      assert(sizeof(double) == sizeof(uint64_t) &&
-             "assuming that double is 64 bits!");
+      static_assert(sizeof(double) == sizeof(uint64_t),
+                    "assuming that double is 64 bits!");
       char Buffer[40];
       APFloat apf = CFP->getValueAPF();
       // Halves and floats are represented in ASCII IR as double, convert.