This is an automated email from the ASF dual-hosted git repository.
raulcd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new ba273ca6ca GH-49569: [CI][Python][C++] Add check targetting Apple
clang on deciding whether to use std::bit_width or std::log2p1 (#49570)
ba273ca6ca is described below
commit ba273ca6ca60bd4f3a552172d4a55d1912ab90f4
Author: Raúl Cumplido <[email protected]>
AuthorDate: Mon Mar 23 09:51:34 2026 +0100
GH-49569: [CI][Python][C++] Add check targetting Apple clang on deciding
whether to use std::bit_width or std::log2p1 (#49570)
### Rationale for this change
Clang 15.0.7 (/opt/homebrew/bin/clang++) - Homebrew LLVM fails compiling
with:
```
FAILED: [code=1]
CMakeFiles/arrow_python.dir/pyarrow/src/arrow/python/arrow_to_pandas.cc.o
/opt/homebrew/bin/ccache /opt/homebrew/bin/clang++ -DARROW_HAVE_NEON
-DARROW_PYTHON_EXPORTING -Darrow_python_EXPORTS
-I/Users/runner/work/arrow/arrow/build/python/pyarrow/src
-I/var/folders/gj/d1t24fg93wbdl854js_qwvb00000gn/T/tmpj20nqu3c/build/pyarrow/src
-I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11
-I/tmp/local/include
-I/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/_core/include
-fno-aligned-new -Wall -Wno-unknown [...]
In file included from
/Users/runner/work/arrow/arrow/build/python/pyarrow/src/arrow/python/arrow_to_pandas.cc:34:
In file included from /tmp/local/include/arrow/array.h:41:
In file included from /tmp/local/include/arrow/array/array_base.h:26:
In file included from /tmp/local/include/arrow/array/data.h:32:
/tmp/local/include/arrow/util/bit_util.h:145:15: error: no member named
'log2p1' in namespace 'std'
return std::log2p1(x - 1);
~~~~~^
1 error generated.
```
This seems to be the case of clang not having `__cpp_lib_bitops` defined
but `std::log2p1` having been removed.
### What changes are included in this PR?
Check for `__apple_build_version__` instead of `__clang__` so non Apple
Clang just uses `std::bit_width`
### Are these changes tested?
Via CI
### Are there any user-facing changes?
No
* GitHub Issue: #49569
Authored-by: Raúl Cumplido <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
---
cpp/src/arrow/util/align_util.h | 3 ++-
cpp/src/arrow/util/bit_util.h | 7 ++++---
cpp/src/arrow/util/rle_encoding_test.cc | 3 ++-
cpp/src/parquet/chunker_internal.cc | 3 ++-
cpp/src/parquet/encoder.cc | 3 ++-
5 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/cpp/src/arrow/util/align_util.h b/cpp/src/arrow/util/align_util.h
index a03a92cc0a..0b23c6d77b 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/bit_util.h b/cpp/src/arrow/util/bit_util.h
index a6eb540fa9..bffc3c14a1 100644
--- a/cpp/src/arrow/util/bit_util.h
+++ b/cpp/src/arrow/util/bit_util.h
@@ -139,9 +139,10 @@ 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.
+// __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);
diff --git a/cpp/src/arrow/util/rle_encoding_test.cc
b/cpp/src/arrow/util/rle_encoding_test.cc
index 5cfa64563a..f33c71c0ad 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 1e1238e835..794075b733 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<uint64_t>(target_size));
#else
auto target_bits = std::bit_width(static_cast<uint64_t>(target_size));
diff --git a/cpp/src/parquet/encoder.cc b/cpp/src/parquet/encoder.cc
index 75eccc96a4..2c70f63b6b 100644
--- a/cpp/src/parquet/encoder.cc
+++ b/cpp/src/parquet/encoder.cc
@@ -1169,7 +1169,8 @@ void DeltaBitPackEncoder<DType>::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<UT>(max_delta) - static_cast<UT>(min_delta));
#else