[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.
Replace most uses of `_LIBCPP_ASSERT` with
`_LIBCPP_ASSERT_UNCATEGORIZED`.
This is done as a prerequisite to introducing hardened mode to libc++.
The idea is to make enabling assertions an opt-in with (somewhat)
fine-grained controls over which categories of assertions are enabled.
The vast majority of assertions are currently uncategorized; the new
macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism
for all kinds of assertions) without enabling all the uncategorized
assertions (in the future; this patch preserves the current behavior).
Differential Revision: https://reviews.llvm.org/D153816
diff --git a/libcxx/src/memory_resource.cpp b/libcxx/src/memory_resource.cpp
index 7f71277..3a80b84 100644
--- a/libcxx/src/memory_resource.cpp
+++ b/libcxx/src/memory_resource.cpp
@@ -175,7 +175,7 @@
void unsynchronized_pool_resource::__adhoc_pool::__do_deallocate(
memory_resource* upstream, void* p, size_t bytes, size_t align) {
- _LIBCPP_ASSERT(__first_ != nullptr, "deallocating a block that was not allocated with this allocator");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__first_ != nullptr, "deallocating a block that was not allocated with this allocator");
if (__first_->__start_ == p) {
__chunk_footer* next = __first_->__next_;
upstream->deallocate(p, __first_->__allocation_size(), __first_->__align_);
@@ -189,7 +189,7 @@
return;
}
}
- _LIBCPP_ASSERT(false, "deallocating a block that was not allocated with this allocator");
+ _LIBCPP_ASSERT_UNCATEGORIZED(false, "deallocating a block that was not allocated with this allocator");
}
}
@@ -230,7 +230,7 @@
}
void* __allocate_in_new_chunk(memory_resource* upstream, size_t block_size, size_t chunk_size) {
- _LIBCPP_ASSERT(chunk_size % block_size == 0, "");
+ _LIBCPP_ASSERT_UNCATEGORIZED(chunk_size % block_size == 0, "");
static_assert(__default_alignment >= alignof(std::max_align_t), "");
static_assert(__default_alignment >= alignof(__chunk_footer), "");
static_assert(__default_alignment >= alignof(__vacancy_header), "");
@@ -401,7 +401,8 @@
if (i == __num_fixed_pools_)
return __adhoc_pool_.__do_deallocate(__res_, p, bytes, align);
else {
- _LIBCPP_ASSERT(__fixed_pools_ != nullptr, "deallocating a block that was not allocated with this allocator");
+ _LIBCPP_ASSERT_UNCATEGORIZED(
+ __fixed_pools_ != nullptr, "deallocating a block that was not allocated with this allocator");
__fixed_pools_[i].__evacuate(p);
}
}