diff --git a/cmake/macro-conf/support/platform/linux/base.cmakedef b/cmake/macro-conf/support/platform/linux/base.cmakedef index 152f7629fe..162a67c545 100644 --- a/cmake/macro-conf/support/platform/linux/base.cmakedef +++ b/cmake/macro-conf/support/platform/linux/base.cmakedef @@ -42,9 +42,6 @@ LONG_LONG_ALLOWED=1 INTEGER_VALUE_REPR_IS_A_HOST_INTEGER=0 TYPE_FOR_AN_INTEGER_VALUE=unsigned long long TYPE_FOR_A_SIGNED_INTEGER_VALUE=long long -MAX_INTEGER_VALUE=9223372036854775807LL -MIN_INTEGER_VALUE=(-MAX_INTEGER_VALUE-1) -MAX_UNSIGNED_INTEGER_VALUE=18446744073709551615ULL FP_LONG_DOUBLE_IS_80BIT_EXTENDED=1 LINKER_CAN_DISCARD_DUPLICATE_DEFINITIONS=1 diff --git a/src/Changes b/src/Changes index de5c529b76..cf653668fe 100644 --- a/src/Changes +++ b/src/Changes @@ -1,5 +1,23 @@ Version 7.1 +10/11/26 [GH #38] +Integer value limits for a 128-bit host integer representation + +When target integers are represented by a 128-bit host integer (for example, +in the macOS CMake configurations), MAX_INTEGER_VALUE, MIN_INTEGER_VALUE, and +MAX_UNSIGNED_INTEGER_VALUE still defaulted to 64-bit limits. As a result, +constant arithmetic on __int128 values that did not fit in 64 bits could be +wrongly diagnosed as overflowing. For example: + + constexpr __int128 s = (__int128)1 << 100; + static_assert(s * 4 == ((__int128)1 << 102), ""); // Previously an error. + +This is now fixed: When __int128 extensions are allowed, the default limits +are those of the 128-bit types. The Linux configurations no longer hard-code +the 64-bit limits, so they also get the 128-bit limits when the integer value +types are changed to the 128-bit types. + + 10/9/26 [GH #27] Clearer diagnostic when auto is deduced from an incomplete type diff --git a/src/defines_linux.h b/src/defines_linux.h index 47fa8d5264..0e6b9ca149 100644 --- a/src/defines_linux.h +++ b/src/defines_linux.h @@ -282,9 +282,6 @@ Linux. #ifndef TYPE_FOR_A_SIGNED_INTEGER_VALUE #define TYPE_FOR_A_SIGNED_INTEGER_VALUE long long #endif /* TYPE_FOR_A_SIGNED_INTEGER_VALUE */ -#define MAX_INTEGER_VALUE 9223372036854775807LL -#define MIN_INTEGER_VALUE (-MAX_INTEGER_VALUE-1) -#define MAX_UNSIGNED_INTEGER_VALUE 18446744073709551615ULL #if defined(__aarch64__) || defined(__riscv) /* 64-bit ARM and RISC-V use a 128-bit long double representation. */ diff --git a/src/targ_def.h b/src/targ_def.h index 50edb81f9e..49d7b7132f 100644 --- a/src/targ_def.h +++ b/src/targ_def.h @@ -1536,6 +1536,9 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value; /* Minimum and maximum values that can be represented in an_integer_value. */ #ifndef MAX_INTEGER_VALUE +#if INT128_EXTENSIONS_ALLOWED +#define MAX_INTEGER_VALUE ((__int128_t)(~(__uint128_t)0 >> 1)) +#else /* !INT128_EXTENSIONS_ALLOWED */ #if LONG_LONG_ALLOWED #ifdef LLONG_MAX #define MAX_INTEGER_VALUE LLONG_MAX @@ -1545,8 +1548,12 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value; #else /* !LONG_LONG_ALLOWED */ #define MAX_INTEGER_VALUE LONG_MAX #endif /* LONG_LONG_ALLOWED */ +#endif /* INT128_EXTENSIONS_ALLOWED */ #endif /* ifndef MAX_INTEGER_VALUE */ #ifndef MIN_INTEGER_VALUE +#if INT128_EXTENSIONS_ALLOWED +#define MIN_INTEGER_VALUE (-MAX_INTEGER_VALUE-1) +#else /* !INT128_EXTENSIONS_ALLOWED */ #if LONG_LONG_ALLOWED #if defined(LLONG_MIN) && LLONG_MIN < LLONG_MAX /*lint !e30*/ /* The preceding condition detects an incorrect definition of LLONG_MIN @@ -1558,8 +1565,12 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value; #else /* !LONG_LONG_ALLOWED */ #define MIN_INTEGER_VALUE LONG_MIN #endif /* LONG_LONG_ALLOWED */ +#endif /* INT128_EXTENSIONS_ALLOWED */ #endif /* ifndef MIN_INTEGER_VALUE */ #ifndef MAX_UNSIGNED_INTEGER_VALUE +#if INT128_EXTENSIONS_ALLOWED +#define MAX_UNSIGNED_INTEGER_VALUE (~(__uint128_t)0) +#else /* !INT128_EXTENSIONS_ALLOWED */ #if LONG_LONG_ALLOWED #ifdef ULLONG_MAX #define MAX_UNSIGNED_INTEGER_VALUE ULLONG_MAX @@ -1569,6 +1580,7 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value; #else /* !LONG_LONG_ALLOWED */ #define MAX_UNSIGNED_INTEGER_VALUE ULONG_MAX #endif /* LONG_LONG_ALLOWED */ +#endif /* INT128_EXTENSIONS_ALLOWED */ #endif /* ifndef MAX_UNSIGNED_INTEGER_VALUE */ #ifndef BITS_IN_AN_INTEGER_VALUE #define BITS_IN_AN_INTEGER_VALUE (sizeof(an_integer_value) * CHAR_BIT)