From 79a2cc13f467a45985b1bc74678303d9aad831dd Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 17 Jan 2025 16:58:16 +0100 Subject: [PATCH] QSimd: clean up some -Wundef warnings While the whole qsimd_p.h file is suppressing -Wundef, the compiler-supports macros are being used elsewhere, and triggering warnings in other people's code (qhash.cpp, qfloat16.cpp, etc.). Amend those macros to do the usual `defined(x) && x` check instead of just checking for `x`. Technically speaking expansion to defined is UB, but expansion of functions is OK on our supported toolchains (we're testing for it). Task-number: QTBUG-132900 Change-Id: I22b76d49aa32afde7f86d4261ccb33442219ac68 Reviewed-by: Thiago Macieira --- src/corelib/global/qsimd_p.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/global/qsimd_p.h b/src/corelib/global/qsimd_p.h index 6723c78ff44..2f1e556f5d3 100644 --- a/src/corelib/global/qsimd_p.h +++ b/src/corelib/global/qsimd_p.h @@ -97,10 +97,10 @@ QT_WARNING_DISABLE_INTEL(103) #include #endif -#define QT_COMPILER_SUPPORTS(x) (QT_COMPILER_SUPPORTS_ ## x - 0) +#define QT_COMPILER_SUPPORTS(x) (defined QT_COMPILER_SUPPORTS_##x && QT_COMPILER_SUPPORTS_##x) #if defined(Q_PROCESSOR_ARM_64) -# define QT_COMPILER_SUPPORTS_HERE(x) ((__ARM_FEATURE_ ## x) || (__ ## x ## __) || QT_COMPILER_SUPPORTS(x)) +# define QT_COMPILER_SUPPORTS_HERE(x) ((defined __ARM_FEATURE_##x && __ARM_FEATURE_##x) || (defined __##x##__ && __##x##__) || QT_COMPILER_SUPPORTS(x)) # if defined(Q_CC_GNU) || defined(Q_CC_CLANG) /* GCC requires attributes for a function */ # define QT_FUNCTION_TARGET(x) __attribute__((__target__(QT_FUNCTION_TARGET_STRING_ ## x))) @@ -109,10 +109,10 @@ QT_WARNING_DISABLE_INTEL(103) # endif #elif defined(Q_PROCESSOR_ARM_32) /* We do not support for runtime CPU feature switching on ARM32 */ -# define QT_COMPILER_SUPPORTS_HERE(x) ((__ARM_FEATURE_ ## x) || (__ ## x ## __)) +# define QT_COMPILER_SUPPORTS_HERE(x) ((defined __ARM_FEATURE_##x && __ARM_FEATURE_##x) || (defined __##x##__ && __##x##__)) # define QT_FUNCTION_TARGET(x) #elif defined(Q_PROCESSOR_MIPS) -# define QT_COMPILER_SUPPORTS_HERE(x) (__ ## x ## __) +# define QT_COMPILER_SUPPORTS_HERE(x) (defined __##x##__ && __##x##__) # define QT_FUNCTION_TARGET(x) # if !defined(__MIPS_DSP__) && defined(__mips_dsp) && defined(Q_PROCESSOR_MIPS_32) # define __MIPS_DSP__ @@ -125,9 +125,9 @@ QT_WARNING_DISABLE_INTEL(103) # define QT_FUNCTION_TARGET(x) #elif defined(Q_PROCESSOR_X86) # if defined(Q_CC_CLANG) && defined(Q_CC_MSVC) && (Q_CC_CLANG < 1900) -# define QT_COMPILER_SUPPORTS_HERE(x) (__ ## x ## __) +# define QT_COMPILER_SUPPORTS_HERE(x) (defined __##x##__ && __##x##__) # else -# define QT_COMPILER_SUPPORTS_HERE(x) ((__ ## x ## __) || QT_COMPILER_SUPPORTS(x)) +# define QT_COMPILER_SUPPORTS_HERE(x) ((defined __##x##__ && __##x##__) || QT_COMPILER_SUPPORTS(x)) # endif # if defined(Q_CC_GNU) || defined(Q_CC_CLANG) /* GCC requires attributes for a function */ @@ -136,7 +136,7 @@ QT_WARNING_DISABLE_INTEL(103) # define QT_FUNCTION_TARGET(x) # endif #else -# define QT_COMPILER_SUPPORTS_HERE(x) (__ ## x ## __) +# define QT_COMPILER_SUPPORTS_HERE(x) (defined __##x##__ && __##x##__) # define QT_FUNCTION_TARGET(x) #endif