Skip to content

Commit 8d67157

Browse files
philnik777aokblast
authored andcommitted
[libc++][C++03] Fix alg.count/count.pass.cpp (llvm#163751)
1 parent b1c98db commit 8d67157

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

libcxx/include/__cxx03/__algorithm/count.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ __count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
5454
if (__first.__ctz_ != 0) {
5555
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
5656
__storage_type __dn = std::min(__clz_f, __n);
57-
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
58-
__r = std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
57+
__storage_type __m = (__storage_type(~0) << __first.__ctz_) & (__storage_type(~0) >> (__clz_f - __dn));
58+
__r = std::__libcpp_popcount<__storage_type>(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
5959
__n -= __dn;
6060
++__first.__seg_;
6161
}
6262
// do middle whole words
6363
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
64-
__r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_));
64+
__r += std::__libcpp_popcount<__storage_type>(std::__invert_if<!_ToCount>(*__first.__seg_));
6565
// do last partial word
6666
if (__n > 0) {
67-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
68-
__r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
67+
__storage_type __m = __storage_type(~0) >> (__bits_per_word - __n);
68+
__r += std::__libcpp_popcount<__storage_type>(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
6969
}
7070
return __r;
7171
}

libcxx/include/__cxx03/__bit/popcount.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// TODO: __builtin_popcountg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10-
// refactor this code to exclusively use __builtin_popcountg.
11-
129
#ifndef _LIBCPP___CXX03___BIT_POPCOUNT_H
1310
#define _LIBCPP___CXX03___BIT_POPCOUNT_H
1411

@@ -25,12 +22,9 @@ _LIBCPP_PUSH_MACROS
2522

2623
_LIBCPP_BEGIN_NAMESPACE_STD
2724

28-
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
29-
30-
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); }
31-
32-
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
33-
return __builtin_popcountll(__x);
25+
template <class _Tp>
26+
_LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(_Tp __v) {
27+
return __builtin_popcountg(__v);
3428
}
3529

3630
_LIBCPP_END_NAMESPACE_STD

libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=20000000
1717
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=80000000
18-
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
1918

2019
#include <algorithm>
2120
#include <cassert>

0 commit comments

Comments
 (0)