Skip to content

Commit 066bf57

Browse files
committed
GH-49569: [CI][Python][C++] Add check for _LIBCPP_VERSION on deciding whether to use std::bit_width or std::log2p1
1 parent d08d5e6 commit 066bf57

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎cpp/src/arrow/util/bit_util.h‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,17 @@ static inline uint64_t TrailingBits(uint64_t v, int num_bits) {
139139
static inline int Log2(uint64_t x) {
140140
// DCHECK_GT(x, 0);
141141

142-
// TODO: We can remove this condition once CRAN upgrades its macOS
143-
// SDK from 11.3.
144-
#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__)
142+
// TODO: We can remove this condition once CRAN upgrades its macOS
143+
// SDK from 11.3.
144+
// On Clang 15.0.7 newer libc++ removed log2p1 but __cpp_lib_bitops isn't defined
145+
// We check the libcpp version to validate whether it's there or not.
146+
// Commit reference landed on 12.0.0:
147+
// https://github.com/llvm/llvm-project/commit/1a036e9cc82a7f6d6f4675d631fa5eecd8748784
148+
// _LIBCPP_VERSION might not be defined in some environments that's why we keep the
149+
// check for __cpp_lib_bitops as well.
150+
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 12000
151+
return std::bit_width(x - 1);
152+
#elif defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__)
145153
return std::log2p1(x - 1);
146154
#else
147155
return std::bit_width(x - 1);

0 commit comments

Comments
 (0)