From 5fbb374a397d22febcee97b08564967afaacf37e Mon Sep 17 00:00:00 2001 From: Matthew Sterrett Date: Wed, 21 May 2025 16:00:22 -0700 Subject: [PATCH v4 6/6] Workaround for clang<19 crash --- src/include/storage/checksum_impl.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/include/storage/checksum_impl.h b/src/include/storage/checksum_impl.h index 4070646e23e..81dfecff17d 100644 --- a/src/include/storage/checksum_impl.h +++ b/src/include/storage/checksum_impl.h @@ -132,7 +132,7 @@ xsave_available(void) __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]); #elif defined(HAVE__CPUID) __cpuid(exx, 1); -#else +#elif defined(__x86_64__) #error cpuid instruction not available #endif return (exx[2] & (1 << 27)) != 0; /* osxsave */ @@ -215,15 +215,10 @@ do { \ * Block checksum algorithm. The page must be adequately aligned * (at least on 4-byte boundary). */ - -#define PG_DECLARE_CHECKSUM_ISA(ISANAME) \ -static uint32 \ -pg_checksum_block_##ISANAME(const PGChecksummablePage *page); #define PG_DEFINE_CHECKSUM_DUMMY(ISANAME) \ static uint32 \ pg_checksum_block_##ISANAME(const PGChecksummablePage *page); \ -pg_attribute_target(#ISANAME) \ static uint32 \ pg_checksum_block_##ISANAME(const PGChecksummablePage *page) \ { \ @@ -267,6 +262,9 @@ pg_checksum_block_##ISANAME(const PGChecksummablePage *page) \ return result; \ } +/* Older Clang versions crash during LTO with this code */ +#if !(__clang_major__) || __clang_major__ >= 19 + PG_DEFINE_CHECKSUM_ISA(default); #ifdef USE_AVX2_WITH_RUNTIME_CHECK PG_DEFINE_CHECKSUM_ISA(avx2); @@ -289,6 +287,15 @@ pg_checksum_block_dispatch(const PGChecksummablePage *page){ return pg_checksum_block(page); } +#else +/* The same as before the patch, for the crashing Clang versions */ +PG_DEFINE_CHECKSUM_ISA(default); +static uint32 pg_checksum_block(const PGChecksummablePage *page) { + return pg_checksum_block_default(page); +} + +#endif + /* * Compute the checksum for a Postgres page. * -- 2.43.0