Skip to content

Commit 86b7fbc

Browse files
Default the integer value limits to 128 bits when __int128 extensions are allowed. [GH #38]
1 parent 43e10b9 commit 86b7fbc

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎cmake/macro-conf/support/platform/linux/base.cmakedef‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ LONG_LONG_ALLOWED=1
4242
INTEGER_VALUE_REPR_IS_A_HOST_INTEGER=0
4343
TYPE_FOR_AN_INTEGER_VALUE=unsigned long long
4444
TYPE_FOR_A_SIGNED_INTEGER_VALUE=long long
45-
MAX_INTEGER_VALUE=9223372036854775807LL
46-
MIN_INTEGER_VALUE=(-MAX_INTEGER_VALUE-1)
47-
MAX_UNSIGNED_INTEGER_VALUE=18446744073709551615ULL
4845
FP_LONG_DOUBLE_IS_80BIT_EXTENDED=1
4946
LINKER_CAN_DISCARD_DUPLICATE_DEFINITIONS=1
5047

‎src/Changes‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
Version 7.1
22

3+
10/11/26 [GH #38]
4+
Integer value limits for a 128-bit host integer representation
5+
6+
When target integers are represented by a 128-bit host integer (for example,
7+
in the macOS CMake configurations), MAX_INTEGER_VALUE, MIN_INTEGER_VALUE, and
8+
MAX_UNSIGNED_INTEGER_VALUE still defaulted to 64-bit limits. As a result,
9+
constant arithmetic on __int128 values that did not fit in 64 bits could be
10+
wrongly diagnosed as overflowing. For example:
11+
12+
constexpr __int128 s = (__int128)1 << 100;
13+
static_assert(s * 4 == ((__int128)1 << 102), ""); // Previously an error.
14+
15+
This is now fixed: When __int128 extensions are allowed, the default limits
16+
are those of the 128-bit types. The Linux configurations no longer hard-code
17+
the 64-bit limits, so they also get the 128-bit limits when the integer value
18+
types are changed to the 128-bit types.
19+
20+
321
10/9/26 [GH #27]
422
Clearer diagnostic when auto is deduced from an incomplete type
523

‎src/defines_linux.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ Linux.
282282
#ifndef TYPE_FOR_A_SIGNED_INTEGER_VALUE
283283
#define TYPE_FOR_A_SIGNED_INTEGER_VALUE long long
284284
#endif /* TYPE_FOR_A_SIGNED_INTEGER_VALUE */
285-
#define MAX_INTEGER_VALUE 9223372036854775807LL
286-
#define MIN_INTEGER_VALUE (-MAX_INTEGER_VALUE-1)
287-
#define MAX_UNSIGNED_INTEGER_VALUE 18446744073709551615ULL
288285

289286
#if defined(__aarch64__) || defined(__riscv)
290287
/* 64-bit ARM and RISC-V use a 128-bit long double representation. */

‎src/targ_def.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,9 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value;
15361536

15371537
/* Minimum and maximum values that can be represented in an_integer_value. */
15381538
#ifndef MAX_INTEGER_VALUE
1539+
#if INT128_EXTENSIONS_ALLOWED
1540+
#define MAX_INTEGER_VALUE ((__int128_t)(~(__uint128_t)0 >> 1))
1541+
#else /* !INT128_EXTENSIONS_ALLOWED */
15391542
#if LONG_LONG_ALLOWED
15401543
#ifdef LLONG_MAX
15411544
#define MAX_INTEGER_VALUE LLONG_MAX
@@ -1545,8 +1548,12 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value;
15451548
#else /* !LONG_LONG_ALLOWED */
15461549
#define MAX_INTEGER_VALUE LONG_MAX
15471550
#endif /* LONG_LONG_ALLOWED */
1551+
#endif /* INT128_EXTENSIONS_ALLOWED */
15481552
#endif /* ifndef MAX_INTEGER_VALUE */
15491553
#ifndef MIN_INTEGER_VALUE
1554+
#if INT128_EXTENSIONS_ALLOWED
1555+
#define MIN_INTEGER_VALUE (-MAX_INTEGER_VALUE-1)
1556+
#else /* !INT128_EXTENSIONS_ALLOWED */
15501557
#if LONG_LONG_ALLOWED
15511558
#if defined(LLONG_MIN) && LLONG_MIN < LLONG_MAX /*lint !e30*/
15521559
/* 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;
15581565
#else /* !LONG_LONG_ALLOWED */
15591566
#define MIN_INTEGER_VALUE LONG_MIN
15601567
#endif /* LONG_LONG_ALLOWED */
1568+
#endif /* INT128_EXTENSIONS_ALLOWED */
15611569
#endif /* ifndef MIN_INTEGER_VALUE */
15621570
#ifndef MAX_UNSIGNED_INTEGER_VALUE
1571+
#if INT128_EXTENSIONS_ALLOWED
1572+
#define MAX_UNSIGNED_INTEGER_VALUE (~(__uint128_t)0)
1573+
#else /* !INT128_EXTENSIONS_ALLOWED */
15631574
#if LONG_LONG_ALLOWED
15641575
#ifdef ULLONG_MAX
15651576
#define MAX_UNSIGNED_INTEGER_VALUE ULLONG_MAX
@@ -1569,6 +1580,7 @@ typedef TYPE_FOR_A_SIGNED_INTEGER_VALUE a_signed_integer_value;
15691580
#else /* !LONG_LONG_ALLOWED */
15701581
#define MAX_UNSIGNED_INTEGER_VALUE ULONG_MAX
15711582
#endif /* LONG_LONG_ALLOWED */
1583+
#endif /* INT128_EXTENSIONS_ALLOWED */
15721584
#endif /* ifndef MAX_UNSIGNED_INTEGER_VALUE */
15731585
#ifndef BITS_IN_AN_INTEGER_VALUE
15741586
#define BITS_IN_AN_INTEGER_VALUE (sizeof(an_integer_value) * CHAR_BIT)

0 commit comments

Comments
 (0)