authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 12:04:57+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 12:04:57+02:00
log820dc9d76726ab9148b49630a1b4371624032918
tree23be73211c3f0fc58fd9b0fc37b4dc8d56ccd95f
parent958faa7031c7b50a544e151fea4d486e1c4926c1
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxx: backport llvm/llvm-project#155476

https://github.com/llvm/llvm-project/pull/155476

3 files changed, 8 insertions(+), 0 deletions(-)

lib/libcxx/include/__algorithm/sort.h+3
...@@ -860,6 +860,9 @@ __sort<__less<long double>&, long double*>(long double*, long double*, __less<lo...@@ -860,6 +860,9 @@ __sort<__less<long double>&, long double*>(long double*, long double*, __less<lo
860template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>860template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
861_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void861_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
862__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {862__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
863 if (__first == __last) // log(0) is undefined, so don't try computing the depth
864 return;
865
863 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;866 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
864 difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first));867 difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first));
865868
lib/libcxx/include/__bit/bit_log2.h+2
...@@ -9,6 +9,7 @@...@@ -9,6 +9,7 @@
9#ifndef _LIBCPP___BIT_BIT_LOG2_H9#ifndef _LIBCPP___BIT_BIT_LOG2_H
10#define _LIBCPP___BIT_BIT_LOG2_H10#define _LIBCPP___BIT_BIT_LOG2_H
1111
12#include <__assert>
12#include <__bit/countl.h>13#include <__bit/countl.h>
13#include <__config>14#include <__config>
14#include <__type_traits/integer_traits.h>15#include <__type_traits/integer_traits.h>
...@@ -23,6 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD...@@ -23,6 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
23template <class _Tp>24template <class _Tp>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT {25_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT {
25 static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type");26 static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type");
27 _LIBCPP_ASSERT_INTERNAL(__t != 0, "logarithm of 0 is undefined");
26 return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);28 return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);
27}29}
2830
lib/libcxx/src/algorithm.cpp+3
...@@ -13,6 +13,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD...@@ -13,6 +13,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1313
14template <class Comp, class RandomAccessIterator>14template <class Comp, class RandomAccessIterator>
15void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {15void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
16 if (first == last) // log(0) is undefined, so don't try computing the depth
17 return;
18
16 auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));19 auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
1720
18 // Only use bitset partitioning for arithmetic types. We should also check21 // Only use bitset partitioning for arithmetic types. We should also check