[libcxx-commits] [libcxx] ec4005f - [libc++][hardening] Mark the remaining stray assertions as uncategorized
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 29 16:33:45 PDT 2023
Author: Konstantin Varlamov
Date: 2023-08-29T16:32:23-07:00
New Revision: ec4005ff879b436ac66b18ca6b28b39b52e6b5f1
URL: https://github.com/llvm/llvm-project/commit/ec4005ff879b436ac66b18ca6b28b39b52e6b5f1
DIFF: https://github.com/llvm/llvm-project/commit/ec4005ff879b436ac66b18ca6b28b39b52e6b5f1.diff
LOG: [libc++][hardening] Mark the remaining stray assertions as uncategorized
This avoids enabling them unconditionally in all hardening modes.
Reviewed By: #libc, Mordante
Differential Revision: https://reviews.llvm.org/D158970
Added:
Modified:
libcxx/include/__algorithm/three_way_comp_ref_type.h
libcxx/include/__mdspan/layout_left.h
libcxx/include/__mdspan/layout_right.h
libcxx/include/__ranges/repeat_view.h
libcxx/src/filesystem/posix_compat.h
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/three_way_comp_ref_type.h b/libcxx/include/__algorithm/three_way_comp_ref_type.h
index 19c102f4c96c30..7731c0fd791d80 100644
--- a/libcxx/include/__algorithm/three_way_comp_ref_type.h
+++ b/libcxx/include/__algorithm/three_way_comp_ref_type.h
@@ -50,7 +50,7 @@ struct __debug_three_way_comp {
__expected = _Order::greater;
if (__o == _Order::greater)
__expected = _Order::less;
- _LIBCPP_ASSERT(__comp_(__l, __r) == __expected, "Comparator does not induce a strict weak ordering");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__comp_(__l, __r) == __expected, "Comparator does not induce a strict weak ordering");
(void)__l;
(void)__r;
}
diff --git a/libcxx/include/__mdspan/layout_left.h b/libcxx/include/__mdspan/layout_left.h
index 7503dcf77d1379..5faae597f6f81f 100644
--- a/libcxx/include/__mdspan/layout_left.h
+++ b/libcxx/include/__mdspan/layout_left.h
@@ -137,8 +137,8 @@ class layout_left::mapping {
// return a value exceeding required_span_size(), which is used to know how large an allocation one needs
// Thus, this is a canonical point in multi-dimensional data structures to make invalid element access checks
// However, mdspan does check this on its own, so for now we avoid double checking in hardened mode
- _LIBCPP_ASSERT(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...),
- "layout_left::mapping: out of bounds indexing");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...),
+ "layout_left::mapping: out of bounds indexing");
array<index_type, extents_type::rank()> __idx_a{static_cast<index_type>(__idx)...};
return [&]<size_t... _Pos>(index_sequence<_Pos...>) {
index_type __res = 0;
diff --git a/libcxx/include/__mdspan/layout_right.h b/libcxx/include/__mdspan/layout_right.h
index 3d814554a1bed4..4f95789a2fafcc 100644
--- a/libcxx/include/__mdspan/layout_right.h
+++ b/libcxx/include/__mdspan/layout_right.h
@@ -136,8 +136,8 @@ class layout_right::mapping {
// return a value exceeding required_span_size(), which is used to know how large an allocation one needs
// Thus, this is a canonical point in multi-dimensional data structures to make invalid element access checks
// However, mdspan does check this on its own, so for now we avoid double checking in hardened mode
- _LIBCPP_ASSERT(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...),
- "layout_right::mapping: out of bounds indexing");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__mdspan_detail::__is_multidimensional_index_in(__extents_, __idx...),
+ "layout_right::mapping: out of bounds indexing");
return [&]<size_t... _Pos>(index_sequence<_Pos...>) {
index_type __res = 0;
((__res = static_cast<index_type>(__idx) + __extents_.extent(_Pos) * __res), ...);
diff --git a/libcxx/include/__ranges/repeat_view.h b/libcxx/include/__ranges/repeat_view.h
index fddf4baac89a08..459a1e229613ac 100644
--- a/libcxx/include/__ranges/repeat_view.h
+++ b/libcxx/include/__ranges/repeat_view.h
@@ -82,13 +82,13 @@ class repeat_view : public view_interface<repeat_view<_Tp, _Bound>> {
requires copy_constructible<_Tp>
: __value_(in_place, __value), __bound_(__bound_sentinel) {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(__bound_ >= 0, "The value of bound must be greater than or equal to 0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__bound_ >= 0, "The value of bound must be greater than or equal to 0");
}
_LIBCPP_HIDE_FROM_ABI constexpr explicit repeat_view(_Tp&& __value, _Bound __bound_sentinel = _Bound())
: __value_(in_place, std::move(__value)), __bound_(__bound_sentinel) {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(__bound_ >= 0, "The value of bound must be greater than or equal to 0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__bound_ >= 0, "The value of bound must be greater than or equal to 0");
}
template <class... _TpArgs, class... _BoundArgs>
@@ -98,7 +98,7 @@ class repeat_view : public view_interface<repeat_view<_Tp, _Bound>> {
: __value_(in_place, std::make_from_tuple<_Tp>(std::move(__value_args))),
__bound_(std::make_from_tuple<_Bound>(std::move(__bound_args))) {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(
+ _LIBCPP_ASSERT_UNCATEGORIZED(
__bound_ >= 0, "The behavior is undefined if Bound is not unreachable_sentinel_t and bound is negative");
}
@@ -161,7 +161,7 @@ class repeat_view<_Tp, _Bound>::__iterator {
_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--() {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(__current_ > 0, "The value of bound must be greater than or equal to 0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__current_ > 0, "The value of bound must be greater than or equal to 0");
--__current_;
return *this;
}
@@ -174,14 +174,14 @@ class repeat_view<_Tp, _Bound>::__iterator {
_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(
diff erence_type __n) {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(__current_ + __n >= 0, "The value of bound must be greater than or equal to 0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__current_ + __n >= 0, "The value of bound must be greater than or equal to 0");
__current_ += __n;
return *this;
}
_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(
diff erence_type __n) {
if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- _LIBCPP_ASSERT(__current_ - __n >= 0, "The value of bound must be greater than or equal to 0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(__current_ - __n >= 0, "The value of bound must be greater than or equal to 0");
__current_ -= __n;
return *this;
}
diff --git a/libcxx/src/filesystem/posix_compat.h b/libcxx/src/filesystem/posix_compat.h
index f11f41552e3916..fb213d9ec18548 100644
--- a/libcxx/src/filesystem/posix_compat.h
+++ b/libcxx/src/filesystem/posix_compat.h
@@ -322,8 +322,8 @@ inline int statvfs(const wchar_t *p, StatVFS *buf) {
inline wchar_t* getcwd([[maybe_unused]] wchar_t* in_buf, [[maybe_unused]] size_t in_size) {
// Only expected to be used with us allocating the buffer.
- _LIBCPP_ASSERT(in_buf == nullptr, "Windows getcwd() assumes in_buf==nullptr");
- _LIBCPP_ASSERT(in_size == 0, "Windows getcwd() assumes in_size==0");
+ _LIBCPP_ASSERT_UNCATEGORIZED(in_buf == nullptr, "Windows getcwd() assumes in_buf==nullptr");
+ _LIBCPP_ASSERT_UNCATEGORIZED(in_size == 0, "Windows getcwd() assumes in_size==0");
size_t buff_size = MAX_PATH + 10;
std::unique_ptr<wchar_t, decltype(&::free)> buff(static_cast<wchar_t*>(malloc(buff_size * sizeof(wchar_t))), &::free);
More information about the libcxx-commits
mailing list