OSDN Git Service

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 f80f6d7..797a898 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 ded48c5..b46ccc9 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 c7e0cba..19059b3 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 bcc561d..129e8ef 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 8459cb1..c0a33ce 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 93a59a6..d4670e4 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.