From 702ffc45d6d3641ee3baf2625a10493b95ce33a7 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 13 Dec 2022 17:59:03 +0100 Subject: [PATCH] Fix clang-cl build with disabled x86 intrinsics clang-cl's intrinsics support is broken, it doesn't declare the AVX2 intrinsics if they are disabled and this doesn't match GCC or MSVC behavior: https://github.com/llvm/llvm-project/issues/53520 This fix allows to disable x86 intrinsiscs during configuration of clang-cl build. clang-cl build is still not guaranteed to work with enabled x86 intrinsics. Change-Id: Icd295f6b4d868adf10bcd425d5280c56b43cb9f7 Reviewed-by: Thiago Macieira --- configure.cmake | 10 ++++++++++ src/corelib/global/qnumeric_p.h | 2 +- src/corelib/global/qsimd.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/configure.cmake b/configure.cmake index 95995a558df..adc3d481b01 100644 --- a/configure.cmake +++ b/configure.cmake @@ -1274,6 +1274,16 @@ if (TEST_architecture_arch STREQUAL x86_64 OR TEST_architecture_arch STREQUAL i3 MESSAGE [=[ All x86 intrinsics and SIMD support were disabled. If this was in error, check the result of the build in config.tests/x86intrin and report at https://bugreports.qt.io. +]=] + ) + elseif (MSVC AND CLANG) + # Warn only + qt_configure_add_report_entry( + TYPE WARNING + CONDITION (NOT QT_FEATURE_x86intrin) + MESSAGE [=[ +x86 intrinsics support is disabled for clang-cl build. This might be necessary due to +https://github.com/llvm/llvm-project/issues/53520 ]=] ) else() diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 9765ce4a319..40c459991c8 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -180,7 +180,7 @@ static inline bool convertDoubleTo(double v, T *value, bool allow_precision_upgr // correct, but Clang, ICC and MSVC don't realize that it's a constant and // the math call stays in the compiled code. -#ifdef Q_PROCESSOR_X86_64 +#if defined(Q_PROCESSOR_X86_64) && defined(__SSE2__) // Of course, UB doesn't apply if we use intrinsics, in which case we are // allowed to dpeend on exactly the processor's behavior. This // implementation uses the truncating conversions from Scalar Double to diff --git a/src/corelib/global/qsimd.h b/src/corelib/global/qsimd.h index 6ed7821e269..4ef925ca337 100644 --- a/src/corelib/global/qsimd.h +++ b/src/corelib/global/qsimd.h @@ -55,7 +55,7 @@ #if defined(Q_PROCESSOR_X86) && defined(Q_CC_MSVC) // MSVC doesn't define __SSE2__, so do it ourselves -# if (defined(_M_X64) || _M_IX86_FP >= 2) +# if (defined(_M_X64) || _M_IX86_FP >= 2) && defined(QT_COMPILER_SUPPORTS_SSE2) # define __SSE__ 1 # define __SSE2__ 1 # endif