[libcxx-commits] [libcxx] 3222670 - [libc++] Fix `__split_buffer_size_layout` bugs (#178341)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 29 10:24:06 PST 2026
Author: Christopher Di Bella
Date: 2026-01-29T13:24:01-05:00
New Revision: 3222670c681cb3d1ac57fbd0faffec8957a7403a
URL: https://github.com/llvm/llvm-project/commit/3222670c681cb3d1ac57fbd0faffec8957a7403a
DIFF: https://github.com/llvm/llvm-project/commit/3222670c681cb3d1ac57fbd0faffec8957a7403a.diff
LOG: [libc++] Fix `__split_buffer_size_layout` bugs (#178341)
As `__split_buffer` doesn't have any unit tests, and because #139632
disassociated adding `__split_buffer` support for both pointer-based and
size-based layouts from its `vector` counterpart, libc++ had no way to
expose `__split_buffer_size_layout` bugs until the size-based vector
patch integrated #139632. This commit fixes the two problems that were
identified while working on #155330.
Added:
Modified:
libcxx/include/__split_buffer
Removed:
################################################################################
diff --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer
index d6176f8ca2749..89c398e525998 100644
--- a/libcxx/include/__split_buffer
+++ b/libcxx/include/__split_buffer
@@ -156,10 +156,8 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT { return *(__end_ - 1); }
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_without_allocator(
- __split_buffer_pointer_layout<__split_buffer<value_type, allocator_type, __split_buffer_pointer_layout>,
- value_type,
- allocator_type>& __other) _NOEXCEPT {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __swap_without_allocator(__split_buffer_pointer_layout& __other) _NOEXCEPT {
std::swap(__front_cap_, __other.__front_cap_);
std::swap(__begin_, __other.__begin_);
std::swap(__back_cap_, __other.__back_cap_);
@@ -263,25 +261,19 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
__set_valid_range(pointer __new_begin, pointer __new_end) _NOEXCEPT {
- // Size-based __split_buffers track their size directly: we need to explicitly update the size
- // when the front is adjusted.
- __size_ -= __new_begin - __begin_;
__begin_ = __new_begin;
__set_sentinel(__new_end);
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
__set_valid_range(pointer __new_begin, size_type __new_size) _NOEXCEPT {
- // Size-based __split_buffers track their size directly: we need to explicitly update the size
- // when the front is adjusted.
- __size_ -= __new_begin - __begin_;
__begin_ = __new_begin;
__set_sentinel(__new_size);
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(pointer __new_end) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__front_cap_ <= __new_end, "__new_end cannot precede __front_cap_");
- __size_ += __new_end - end();
+ __size_ = __new_end - __begin_;
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __set_sentinel(size_type __new_size) _NOEXCEPT {
@@ -312,10 +304,8 @@ public:
return __begin_[__size_ - 1];
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_without_allocator(
- __split_buffer_pointer_layout<__split_buffer<value_type, allocator_type, __split_buffer_pointer_layout>,
- value_type,
- allocator_type>& __other) _NOEXCEPT {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __swap_without_allocator(__split_buffer_size_layout& __other) _NOEXCEPT {
std::swap(__front_cap_, __other.__front_cap_);
std::swap(__begin_, __other.__begin_);
std::swap(__cap_, __other.__cap_);
@@ -585,7 +575,7 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
__swap_without_allocator(__split_buffer<value_type, allocator_type, _Layout>& __other) _NOEXCEPT {
- __base_type::__swap_without_allocator(__other);
+ __base_type::__swap_without_allocator(static_cast<__base_type&>(__other));
}
private:
More information about the libcxx-commits
mailing list