From 457c891775a7397bdb0376bb1031e6e027af1c48 Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Fri, 31 May 2024 08:29:56 -0700 Subject: [PATCH] remove HWY_HAS_INCLUDE - mishandled by clang PiperOrigin-RevId: 639043353 --- hwy/base.h | 14 ++++++++++++-- hwy/detect_compiler_arch.h | 6 +----- hwy/detect_targets.h | 11 +++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/hwy/base.h b/hwy/base.h index d4eed94fac..7b13b0dd6e 100644 --- a/hwy/base.h +++ b/hwy/base.h @@ -53,9 +53,19 @@ #endif // !HWY_IDE -#ifndef HWY_HAVE_CXX20_THREE_WAY_COMPARE // allow opt-out +#ifndef HWY_HAVE_COMPARE_HEADER // allow override +#define HWY_HAVE_COMPARE_HEADER 0 +#if defined(__has_include) // note: wrapper macro fails on Clang ~17 +#if __has_include() +#undef HWY_HAVE_COMPARE_HEADER +#define HWY_HAVE_COMPARE_HEADER 1 +#endif // __has_include +#endif // defined(__has_include) +#endif // HWY_HAVE_COMPARE_HEADER + +#ifndef HWY_HAVE_CXX20_THREE_WAY_COMPARE // allow override #if !defined(HWY_NO_LIBCXX) && defined(__cpp_impl_three_way_comparison) && \ - __cpp_impl_three_way_comparison >= 201907L && HWY_HAS_INCLUDE() + __cpp_impl_three_way_comparison >= 201907L && HWY_HAVE_COMPARE_HEADER #include #define HWY_HAVE_CXX20_THREE_WAY_COMPARE 1 #else diff --git a/hwy/detect_compiler_arch.h b/hwy/detect_compiler_arch.h index 262048d087..94b49cb728 100644 --- a/hwy/detect_compiler_arch.h +++ b/hwy/detect_compiler_arch.h @@ -166,11 +166,7 @@ #define HWY_HAS_FEATURE(name) 0 #endif -#ifdef __has_include -#define HWY_HAS_INCLUDE(header) __has_include(header) -#else -#define HWY_HAS_INCLUDE(header) 0 -#endif +// NOTE: clang ~17 does not correctly handle wrapping __has_include in a macro. #if HWY_COMPILER_MSVC && defined(_MSVC_LANG) && _MSVC_LANG > __cplusplus #define HWY_CXX_LANG _MSVC_LANG diff --git a/hwy/detect_targets.h b/hwy/detect_targets.h index c5aa009fad..db4c786489 100644 --- a/hwy/detect_targets.h +++ b/hwy/detect_targets.h @@ -577,19 +577,22 @@ #endif // Defining one of HWY_COMPILE_ONLY_* will trump HWY_COMPILE_ALL_ATTAINABLE. -// Allow opting out, and without a guarantee of success, opting-in. -#ifndef HWY_HAVE_AUXV +#ifndef HWY_HAVE_AUXV // allow override #ifdef TOOLCHAIN_MISS_SYS_AUXV_H #define HWY_HAVE_AUXV 0 // CMake failed to find the header // glibc 2.16 added auxv, but checking for that requires features.h, and we do // not want to include system headers here. Instead check for the header // directly, which has been supported at least since GCC 5.4 and Clang 3. +#elif defined(__has_include) // note: wrapper macro fails on Clang ~17 // clang-format off -#elif HWY_HAS_INCLUDE() +#if __has_include() // clang-format on #define HWY_HAVE_AUXV 1 // header present #else -#define HWY_HAVE_AUXV 0 // header not present, or non Clang/GCC compiler +#define HWY_HAVE_AUXV 0 // header not present +#endif // __has_include +#else // compiler lacks __has_include +#define HWY_HAVE_AUXV 0 #endif #endif // HWY_HAVE_AUXV