[llvm] r204011 - Make some assertions on constant expressions static.
Benjamin Kramer
benny.kra at googlemail.com
Sat Mar 15 11:47:08 PDT 2014
Author: d0k
Date: Sat Mar 15 13:47:07 2014
New Revision: 204011
URL: http://llvm.org/viewvc/llvm-project?rev=204011&view=rev
Log:
Make some assertions on constant expressions static.
Modified:
llvm/trunk/include/llvm/ADT/SparseMultiSet.h
llvm/trunk/include/llvm/ADT/SparseSet.h
llvm/trunk/include/llvm/Support/ArrayRecycler.h
llvm/trunk/include/llvm/Support/Recycler.h
llvm/trunk/lib/DebugInfo/DWARFDebugArangeSet.cpp
llvm/trunk/lib/IR/AsmWriter.cpp
Modified: llvm/trunk/include/llvm/ADT/SparseMultiSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SparseMultiSet.h?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SparseMultiSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SparseMultiSet.h Sat Mar 15 13:47:07 2014
@@ -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]);
Modified: llvm/trunk/include/llvm/ADT/SparseSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SparseSet.h?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SparseSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SparseSet.h Sat Mar 15 13:47:07 2014
@@ -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]);
Modified: llvm/trunk/include/llvm/Support/ArrayRecycler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ArrayRecycler.h?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ArrayRecycler.h (original)
+++ llvm/trunk/include/llvm/Support/ArrayRecycler.h Sat Mar 15 13:47:07 2014
@@ -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);
Modified: llvm/trunk/include/llvm/Support/Recycler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Recycler.h?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Recycler.h (original)
+++ llvm/trunk/include/llvm/Support/Recycler.h Sat Mar 15 13:47:07 2014
@@ -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));
Modified: llvm/trunk/lib/DebugInfo/DWARFDebugArangeSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugArangeSet.cpp?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugArangeSet.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugArangeSet.cpp Sat Mar 15 13:47:07 2014
@@ -67,7 +67,9 @@ DWARFDebugArangeSet::extract(DataExtract
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)) {
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=204011&r1=204010&r2=204011&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Sat Mar 15 13:47:07 2014
@@ -811,8 +811,8 @@ static void WriteConstantInternal(raw_os
// 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.
More information about the llvm-commits
mailing list