summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-03-15 18:47:07 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-03-15 18:47:07 +0000
commit571832b930951b0d8d73f0cafea77fd23b225baf (patch)
tree34cf4ad94c9f6d10893a0a646ccbe0043579ea22 /include
parent80d3b1e7087421008df3c6794b60beaf395efbeb (diff)
downloadllvm-571832b930951b0d8d73f0cafea77fd23b225baf.tar.gz
llvm-571832b930951b0d8d73f0cafea77fd23b225baf.tar.bz2
llvm-571832b930951b0d8d73f0cafea77fd23b225baf.tar.xz
Make some assertions on constant expressions static.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204011 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/SparseMultiSet.h7
-rw-r--r--include/llvm/ADT/SparseSet.h7
-rw-r--r--include/llvm/Support/ArrayRecycler.h5
-rw-r--r--include/llvm/Support/Recycler.h8
4 files changed, 15 insertions, 12 deletions
diff --git a/include/llvm/ADT/SparseMultiSet.h b/include/llvm/ADT/SparseMultiSet.h
index f80f6d7153..797a898dcc 100644
--- a/include/llvm/ADT/SparseMultiSet.h
+++ b/include/llvm/ADT/SparseMultiSet.h
@@ -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]);
diff --git a/include/llvm/ADT/SparseSet.h b/include/llvm/ADT/SparseSet.h
index ded48c5746..b46ccc9375 100644
--- a/include/llvm/ADT/SparseSet.h
+++ b/include/llvm/ADT/SparseSet.h
@@ -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]);
diff --git a/include/llvm/Support/ArrayRecycler.h b/include/llvm/Support/ArrayRecycler.h
index c7e0cba279..19059b32cd 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<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);
diff --git a/include/llvm/Support/Recycler.h b/include/llvm/Support/Recycler.h
index bcc561db2d..129e8efd2b 100644
--- a/include/llvm/Support/Recycler.h
+++ b/include/llvm/Support/Recycler.h
@@ -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));