From 615974e35a9e552b3a7550c10e5b47ebcdd10dc0 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 19 Jun 2026 16:31:23 -0400 Subject: [PATCH] Fix GCC macOS downstream builds Signed-off-by: Juan Cruz Viotti --- src/core/crypto/crypto_crc32.cc | 34 ++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/core/crypto/crypto_crc32.cc b/src/core/crypto/crypto_crc32.cc index d28615603..d6c570406 100644 --- a/src/core/crypto/crypto_crc32.cc +++ b/src/core/crypto/crypto_crc32.cc @@ -11,10 +11,38 @@ // feature macro that the compiler sets when the right -march or -mcpu is in // effect #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) -#include // __crc32b, __crc32d #define SOURCEMETA_CORE_CRYPTO_CRC32_ARM 1 #endif +// The CRC32 operations are reached through compiler builtins rather than the +// intrinsics. On aarch64-apple-darwin, GCC's header fails to +// compile under warnings-as-errors because of unrelated random number +// intrinsics whose inline bodies pass a pointer of the wrong width, and merely +// including the header type-checks those bodies even though we never call them +#ifdef SOURCEMETA_CORE_CRYPTO_CRC32_ARM +namespace { + +auto crc32_hardware_word(const std::uint32_t checksum, + const std::uint64_t value) noexcept -> std::uint32_t { +#if defined(__clang__) + return __builtin_arm_crc32d(checksum, value); +#else + return __builtin_aarch64_crc32x(checksum, value); +#endif +} + +auto crc32_hardware_byte(const std::uint32_t checksum, + const std::uint8_t value) noexcept -> std::uint32_t { +#if defined(__clang__) + return __builtin_arm_crc32b(checksum, value); +#else + return __builtin_aarch64_crc32b(checksum, value); +#endif +} + +} // namespace +#endif + #ifndef SOURCEMETA_CORE_CRYPTO_CRC32_ARM namespace { @@ -68,12 +96,12 @@ auto crc32_update(const std::uint32_t previous, const std::string_view input) while (remaining >= 8) { std::uint64_t chunk{0}; std::memcpy(&chunk, data, sizeof(chunk)); - checksum = __crc32d(checksum, chunk); + checksum = crc32_hardware_word(checksum, chunk); data += 8; remaining -= 8; } while (remaining > 0) { - checksum = __crc32b(checksum, *data++); + checksum = crc32_hardware_byte(checksum, *data++); --remaining; } return checksum ^ 0xFFFFFFFFu;