From: Benjamin Kramer Date: Sat, 15 Mar 2014 18:47:07 +0000 (+0000) Subject: Make some assertions on constant expressions static. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=571832b930951b0d8d73f0cafea77fd23b225baf;p=oota-llvm.git Make some assertions on constant expressions static. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204011 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/SparseMultiSet.h b/include/llvm/ADT/SparseMultiSet.h index f80f6d7153f..797a898dcc3 100644 --- a/include/llvm/ADT/SparseMultiSet.h +++ b/include/llvm/ADT/SparseMultiSet.h @@ -76,6 +76,10 @@ template, typename SparseT = uint8_t> class SparseMultiSet { + static_assert(std::numeric_limits::is_integer && + !std::numeric_limits::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::is_integer && - !std::numeric_limits::is_signed && - "SparseT must be an unsigned integer type"); const unsigned Stride = std::numeric_limits::max() + 1u; for (unsigned i = Sparse[Idx], e = Dense.size(); i < e; i += Stride) { const unsigned FoundIdx = sparseIndex(Dense[i]); diff --git a/include/llvm/ADT/SparseSet.h b/include/llvm/ADT/SparseSet.h index ded48c5746a..b46ccc93754 100644 --- a/include/llvm/ADT/SparseSet.h +++ b/include/llvm/ADT/SparseSet.h @@ -118,6 +118,10 @@ template, typename SparseT = uint8_t> class SparseSet { + static_assert(std::numeric_limits::is_integer && + !std::numeric_limits::is_signed, + "SparseT must be an unsigned integer type"); + typedef typename KeyFunctorT::argument_type KeyT; typedef SmallVector DenseT; DenseT Dense; @@ -198,9 +202,6 @@ public: /// iterator findIndex(unsigned Idx) { assert(Idx < Universe && "Key out of range"); - assert(std::numeric_limits::is_integer && - !std::numeric_limits::is_signed && - "SparseT must be an unsigned integer type"); const unsigned Stride = std::numeric_limits::max() + 1u; for (unsigned i = Sparse[Idx], e = size(); i < e; i += Stride) { const unsigned FoundIdx = ValIndexOf(Dense[i]); diff --git a/include/llvm/Support/ArrayRecycler.h b/include/llvm/Support/ArrayRecycler.h index c7e0cba279e..19059b32cd3 100644 --- a/include/llvm/Support/ArrayRecycler.h +++ b/include/llvm/Support/ArrayRecycler.h @@ -35,6 +35,9 @@ class ArrayRecycler { FreeList *Next; }; + static_assert(Align >= AlignOf::Alignment, "Object underaligned"); + static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small"); + // Keep a free list for each array size. SmallVector 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::Alignment && "Object underaligned"); FreeList *Entry = reinterpret_cast(Ptr); if (Idx >= Bucket.size()) Bucket.resize(size_t(Idx) + 1); diff --git a/include/llvm/Support/Recycler.h b/include/llvm/Support/Recycler.h index bcc561db2d5..129e8efd2b2 100644 --- a/include/llvm/Support/Recycler.h +++ b/include/llvm/Support/Recycler.h @@ -100,10 +100,10 @@ public: template SubClass *Allocate(AllocatorType &Allocator) { - assert(sizeof(SubClass) <= Size && - "Recycler allocation size is less than object size!"); - assert(AlignOf::Alignment <= Align && - "Recycler allocation alignment is less than object alignment!"); + static_assert(AlignOf::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(FreeList.remove(FreeList.begin())) : static_cast(Allocator.Allocate(Size, Align)); diff --git a/lib/DebugInfo/DWARFDebugArangeSet.cpp b/lib/DebugInfo/DWARFDebugArangeSet.cpp index 8459cb13789..c0a33ceaf24 100644 --- a/lib/DebugInfo/DWARFDebugArangeSet.cpp +++ b/lib/DebugInfo/DWARFDebugArangeSet.cpp @@ -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)) { diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 93a59a63c89..d4670e4bc6c 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -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.