From d563ec3fba7cc7f435bf75e7569dc253cd95013a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Matysiak?= Date: Thu, 22 Aug 2024 16:00:41 +0200 Subject: [PATCH] Introduce QT_COMPILER_SUPPORTS_INT128 in qsystemdetection c661dbd42d87f151e0c6f9e50fb21a137dad850c injected `QT_NO_INT128` into every TU when compiling for VxWorks. VxWorks uses a custom stdlib implementation that does not support 128bit ints and at the same time they use an off the shelf Clang that defines `__SIZEOF_INT128__` which is used to detect if 128b ints are available. This resulted in Qt falsely assuming that 128b ints are available. Detect if 128bit are available instead of injecting `QT_NO_INT128` and define `QT_COMPILER_SUPPORTS_INT128`, use it instead of directly checking `__SIZEOF_INT128__`. Task-number: QTBUG-115777 Change-Id: I7531ebe780b4bdd78b42daf8dae0e522a316a88e Reviewed-by: Marc Mutz (cherry picked from commit 5a10744bb4afc0c95b1b7bbba8848cf14b0bad00) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPlatformTargetHelpers.cmake | 9 --------- src/corelib/global/qsystemdetection.h | 8 ++++++++ src/corelib/global/qtypes.cpp | 2 +- src/corelib/global/qtypes.h | 5 +++-- src/corelib/plugin/quuid.h | 3 ++- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cmake/QtPlatformTargetHelpers.cmake b/cmake/QtPlatformTargetHelpers.cmake index 0b2025666de..90f159c06c6 100644 --- a/cmake/QtPlatformTargetHelpers.cmake +++ b/cmake/QtPlatformTargetHelpers.cmake @@ -47,15 +47,6 @@ function(qt_internal_setup_public_platform_target) target_compile_options(Platform INTERFACE "$<$:-fno-direct-access-external-data>") endif() - # Qt checks if a given platform supports 128 bit integers - # by checking if __SIZEOF_128__ is defined - # VXWORKS doesn't support 128 bit integers - # but it uses clang which defines __SIZEOF_128__ - # which breaks the detection mechanism - if(VXWORKS) - target_compile_definitions(Platform INTERFACE "-DQT_NO_INT128") - endif() - qt_set_msvc_cplusplus_options(Platform INTERFACE) # Propagate minimum C++ 17 via Platform to Qt consumers (apps), after the global features diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h index b29f2e94964..0cbcef27407 100644 --- a/src/corelib/global/qsystemdetection.h +++ b/src/corelib/global/qsystemdetection.h @@ -239,4 +239,12 @@ # define Q_OF_MACH_O #endif +#if defined(__SIZEOF_INT128__) +// Compiler used in VxWorks SDK declares __SIZEOF_INT128__ but VxWorks doesn't support this type, +// so we can't rely solely on compiler here. +#if !defined(Q_OS_VXWORKS) +# define QT_COMPILER_SUPPORTS_INT128 __SIZEOF_INT128__ +#endif +#endif // defined(__SIZEOF_INT128__) + #endif // QSYSTEMDETECTION_H diff --git a/src/corelib/global/qtypes.cpp b/src/corelib/global/qtypes.cpp index 9a4616b9d89..bd01498ce2d 100644 --- a/src/corelib/global/qtypes.cpp +++ b/src/corelib/global/qtypes.cpp @@ -503,7 +503,7 @@ static_assert(sizeof(size_t) == sizeof(qsizetype)); // implied by the definition static_assert((std::is_same::value)); static_assert(std::is_same_v); -#ifdef __SIZEOF_INT128__ +#ifdef QT_COMPILER_SUPPORTS_INT128 # ifndef QT_SUPPORTS_INT128 # error Qt needs to be compiled in a mode that enables INT128 \ if the compiler supports it in principle. diff --git a/src/corelib/global/qtypes.h b/src/corelib/global/qtypes.h index d5dffe60477..65bf01fac14 100644 --- a/src/corelib/global/qtypes.h +++ b/src/corelib/global/qtypes.h @@ -6,6 +6,7 @@ #define QTYPES_H #include +#include #include #include @@ -66,8 +67,8 @@ typedef quint64 qulonglong; #ifdef Q_QDOC // QDoc always needs to see the typedefs # define QT_SUPPORTS_INT128 16 -#elif defined(__SIZEOF_INT128__) && !defined(QT_NO_INT128) -# define QT_SUPPORTS_INT128 __SIZEOF_INT128__ +#elif defined(QT_COMPILER_SUPPORTS_INT128) && !defined(QT_NO_INT128) +# define QT_SUPPORTS_INT128 QT_COMPILER_SUPPORTS_INT128 # if defined(__GLIBCXX__) && defined(__STRICT_ANSI__) // -ansi/-std=c++NN instead of gnu++NN # undef QT_SUPPORTS_INT128 // breaks on libstdc++ # endif diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 49f2b6749cd..435b7bb572d 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -7,6 +7,7 @@ #include #include #include +#include #if defined(Q_OS_WIN) || defined(Q_QDOC) #ifndef GUID_DEFINED @@ -61,7 +62,7 @@ public: quint16 data16[8]; quint32 data32[4]; quint64 data64[2]; -#if defined(__SIZEOF_INT128__) +#if defined(QT_COMPILER_SUPPORTS_INT128) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wpedantic") // ISO C++ does not support ‘__int128’ for ‘data128’ unsigned __int128 data128[1];