Use QT_SUPPORTS_INT128 macro to handle 128-bit integral types

Introduce QT_SUPPORTS_INT128 and QT_NO_INT128 marcos to handle 128-bit
types. These macros allow to undef Qt's own 128-bit types and the
related code, but keep the compiler definitions unchanged.

This is required for Qt Bluetooth, where we need to use
QT_BLUETOOTH_REMOVED_SINCE to get rid of the APIs using
QtBluetooth-specific struct quint128 which clashes with the 128-bit
types. The idea is to use QT_NO_INT128 in Qt Bluetooth's
removed_api.cpp instead of directly undef'ing __SIZEOF_INT128__,
because the latter is UB.

This commit amends befda1acca.

Pick-to: 6.6
Change-Id: Ia2c110b5744c3aaa53eda39fb44984cf5a01fac2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ivan Solovev 2023-07-24 18:47:15 +02:00
parent 8cedef62cf
commit eb0abd9789
4 changed files with 13 additions and 7 deletions

View File

@ -105,7 +105,7 @@ inline constexpr T qbswap(T source)
return T(qbswap_helper(typename QIntegerForSizeof<T>::Unsigned(source)));
}
#ifdef __SIZEOF_INT128__
#ifdef QT_SUPPORTS_INT128
// extra definitions for q(u)int128, in case std::is_integral_v<~~> == false
inline constexpr quint128 qbswap(quint128 source)
{

View File

@ -58,7 +58,13 @@ typedef unsigned long long quint64; /* 64 bit unsigned */
typedef qint64 qlonglong;
typedef quint64 qulonglong;
#if defined(__SIZEOF_INT128__)
#if defined(__SIZEOF_INT128__) && !defined(QT_NO_INT128)
# define QT_SUPPORTS_INT128 __SIZEOF_INT128__
#else
# undef QT_SUPPORTS_INT128
#endif
#if defined(QT_SUPPORTS_INT128)
__extension__ typedef __int128_t qint128;
__extension__ typedef __uint128_t quint128;
#endif
@ -107,7 +113,7 @@ template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qin
template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
#if defined(__SIZEOF_INT128__)
#if defined(QT_SUPPORTS_INT128)
template <> struct QIntegerForSize<16> { typedef quint128 Unsigned; typedef qint128 Signed; };
#endif
template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };

View File

@ -60,7 +60,7 @@ public:
quint16 data16[8];
quint32 data32[4];
quint64 data64[2];
#ifdef __SIZEOF_INT128__
#ifdef QT_SUPPORTS_INT128
quint128 data128[1];
#endif
@ -100,7 +100,7 @@ public:
bool isNull() const noexcept;
#ifdef __SIZEOF_INT128__
#ifdef QT_SUPPORTS_INT128
constexpr QUuid(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept;
constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept;
#endif
@ -242,7 +242,7 @@ inline QUuid QUuid::fromBytes(const void *bytes, QSysInfo::Endian order) noexcep
return QUuid(result, order);
}
#ifdef __SIZEOF_INT128__
#ifdef QT_SUPPORTS_INT128
constexpr QUuid::QUuid(quint128 uuid, QSysInfo::Endian order) noexcept
: QUuid()
{

View File

@ -248,7 +248,7 @@ void tst_QUuid::id128()
void tst_QUuid::uint128()
{
#ifdef __SIZEOF_INT128__
#ifdef QT_SUPPORTS_INT128
constexpr quint128 u = quint128(Q_UINT64_C(0xfc69b59ecc344436)) << 64
| Q_UINT64_C(0xa43cee95d128b8c5); // This is LE
constexpr quint128 be = qToBigEndian(u);