From 066bf57d319e27bdd3aba6ad2ac4dac52b308099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 20 Mar 2026 11:14:35 +0100 Subject: [PATCH 1/3] GH-49569: [CI][Python][C++] Add check for _LIBCPP_VERSION on deciding whether to use std::bit_width or std::log2p1 --- cpp/src/arrow/util/bit_util.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/util/bit_util.h b/cpp/src/arrow/util/bit_util.h index a6eb540fa9be..ffa65f3d6cfc 100644 --- a/cpp/src/arrow/util/bit_util.h +++ b/cpp/src/arrow/util/bit_util.h @@ -139,9 +139,17 @@ static inline uint64_t TrailingBits(uint64_t v, int num_bits) { static inline int Log2(uint64_t x) { // DCHECK_GT(x, 0); - // TODO: We can remove this condition once CRAN upgrades its macOS - // SDK from 11.3. -#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) +// TODO: We can remove this condition once CRAN upgrades its macOS +// SDK from 11.3. +// On Clang 15.0.7 newer libc++ removed log2p1 but __cpp_lib_bitops isn't defined +// We check the libcpp version to validate whether it's there or not. +// Commit reference landed on 12.0.0: +// https://github.com/llvm/llvm-project/commit/1a036e9cc82a7f6d6f4675d631fa5eecd8748784 +// _LIBCPP_VERSION might not be defined in some environments that's why we keep the +// check for __cpp_lib_bitops as well. +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 12000 + return std::bit_width(x - 1); +#elif defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) return std::log2p1(x - 1); #else return std::bit_width(x - 1); From a982f1940622872d82ed1d8ee2aa70a4110f6b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 20 Mar 2026 11:44:08 +0100 Subject: [PATCH 2/3] Try using __apple_build_version__ instead of __clang__ --- cpp/src/arrow/util/bit_util.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cpp/src/arrow/util/bit_util.h b/cpp/src/arrow/util/bit_util.h index ffa65f3d6cfc..bffc3c14a106 100644 --- a/cpp/src/arrow/util/bit_util.h +++ b/cpp/src/arrow/util/bit_util.h @@ -141,15 +141,8 @@ static inline int Log2(uint64_t x) { // TODO: We can remove this condition once CRAN upgrades its macOS // SDK from 11.3. -// On Clang 15.0.7 newer libc++ removed log2p1 but __cpp_lib_bitops isn't defined -// We check the libcpp version to validate whether it's there or not. -// Commit reference landed on 12.0.0: -// https://github.com/llvm/llvm-project/commit/1a036e9cc82a7f6d6f4675d631fa5eecd8748784 -// _LIBCPP_VERSION might not be defined in some environments that's why we keep the -// check for __cpp_lib_bitops as well. -#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 12000 - return std::bit_width(x - 1); -#elif defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) +// __apple_build_version__ should be defined only on Apple clang +#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) return std::log2p1(x - 1); #else return std::bit_width(x - 1); From 4736f0853912a067dec0348168f7525ae2b7de95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 20 Mar 2026 13:47:34 +0100 Subject: [PATCH 3/3] Add the change into other places we perform the check --- cpp/src/arrow/util/align_util.h | 3 ++- cpp/src/arrow/util/rle_encoding_test.cc | 3 ++- cpp/src/parquet/chunker_internal.cc | 3 ++- cpp/src/parquet/encoder.cc | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/util/align_util.h b/cpp/src/arrow/util/align_util.h index a03a92cc0a66..0b23c6d77bd9 100644 --- a/cpp/src/arrow/util/align_util.h +++ b/cpp/src/arrow/util/align_util.h @@ -46,7 +46,8 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t* data, int64_t bit_of int64_t length) { // TODO: We can remove this condition once CRAN upgrades its macOS // SDK from 11.3. -#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) + // __apple_build_version__ should be defined only on Apple clang +#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) static_assert((ALIGN_IN_BYTES != 0) && ((ALIGN_IN_BYTES & (ALIGN_IN_BYTES - 1)) == 0), "ALIGN_IN_BYTES should be a positive power of two"); #else diff --git a/cpp/src/arrow/util/rle_encoding_test.cc b/cpp/src/arrow/util/rle_encoding_test.cc index 5cfa64563a09..f33c71c0ad28 100644 --- a/cpp/src/arrow/util/rle_encoding_test.cc +++ b/cpp/src/arrow/util/rle_encoding_test.cc @@ -918,7 +918,8 @@ TEST(BitRle, Random) { } // TODO: We can remove this condition once CRAN upgrades its macOS // SDK from 11.3. -#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) + // __apple_build_version__ should be defined only on Apple clang +#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) if (!CheckRoundTrip(values, std::log2p1(values.size()))) { #else if (!CheckRoundTrip(values, std::bit_width(values.size()))) { diff --git a/cpp/src/parquet/chunker_internal.cc b/cpp/src/parquet/chunker_internal.cc index 1e1238e83504..794075b73379 100644 --- a/cpp/src/parquet/chunker_internal.cc +++ b/cpp/src/parquet/chunker_internal.cc @@ -88,7 +88,8 @@ uint64_t CalculateMask(int64_t min_chunk_size, int64_t max_chunk_size, int norm_ // by taking the floor(log2(target_size)) // TODO: We can remove this condition once CRAN upgrades its macOS // SDK from 11.3. -#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) + // __apple_build_version__ should be defined only on Apple clang +#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) auto target_bits = std::log2p1(static_cast(target_size)); #else auto target_bits = std::bit_width(static_cast(target_size)); diff --git a/cpp/src/parquet/encoder.cc b/cpp/src/parquet/encoder.cc index 75eccc96a442..2c70f63b6b8e 100644 --- a/cpp/src/parquet/encoder.cc +++ b/cpp/src/parquet/encoder.cc @@ -1169,7 +1169,8 @@ void DeltaBitPackEncoder::FlushBlock() { // See overflow comment above. // TODO: We can remove this condition once CRAN upgrades its macOS // SDK from 11.3. -#if defined(__clang__) && !defined(__cpp_lib_bitops) && !defined(__EMSCRIPTEN__) + // __apple_build_version__ should be defined only on Apple clang +#if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) const auto bit_width = bit_width_data[i] = std::log2p1(static_cast(max_delta) - static_cast(min_delta)); #else