From: Philipp Tomsich Date: Fri, 3 Jul 2026 18:16:38 +0000 (+0200) Subject: tree-optimization/124545 - fix pr124545-2.c on ilp32 targets X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d7c74258d3a4b95cd5022acd5fa51381d922a40;p=thirdparty%2Fgcc.git tree-optimization/124545 - fix pr124545-2.c on ilp32 targets The uns_carry() helper used "unsigned int" (32-bit) as the narrow type and "unsigned long" as the wide type. Switch to __UINT32_TYPE__ / __UINT64_TYPE__ throughout so that the narrow-vs-wide test is target-independent. PR tree-optimization/124545 gcc/testsuite/ChangeLog: * gcc.dg/pr124545-2.c: Use __UINT32_TYPE__ / __UINT64_TYPE__ instead of unsigned int/long/long long so the runtime check works on ILP32 targets. Reported-by: Torbjörn SVENSSON Tested-by: Torbjörn SVENSSON Signed-off-by: Philipp Tomsich --- diff --git a/gcc/testsuite/gcc.dg/pr124545-2.c b/gcc/testsuite/gcc.dg/pr124545-2.c index b4806567acc..990f509d349 100644 --- a/gcc/testsuite/gcc.dg/pr124545-2.c +++ b/gcc/testsuite/gcc.dg/pr124545-2.c @@ -4,7 +4,9 @@ computed value. In particular it must NOT fire when CST is not representable in the inner type (which would silently drop the bits above the inner precision), and it must stay correct for unsigned - inner types where the narrow operation wraps. */ + inner types where the narrow operation wraps. Uses __UINT{32,64}_TYPE__ + rather than unsigned {int,long} so that the narrow-vs-wide contrast is + independent of ILP32 vs LP64. */ /* { dg-do run } */ /* { dg-options "-O2" } */ @@ -13,23 +15,23 @@ __attribute__((noipa)) int oor_eq (int a) { - return ((unsigned long long) a + 0x100000000ULL) == (unsigned long long) a; + return ((__UINT64_TYPE__) a + 0x100000000ULL) == (__UINT64_TYPE__) a; } -__attribute__((noipa)) unsigned long long +__attribute__((noipa)) __UINT64_TYPE__ oor_val (int a) { - return (unsigned long long) a + 0x100000000ULL; + return (__UINT64_TYPE__) a + 0x100000000ULL; } /* Unsigned inner: narrow add wraps mod 2^32; the widened add does not. The result must match the wide arithmetic for every input. */ __attribute__((noipa)) int -uns_carry (unsigned int a) +uns_carry (__UINT32_TYPE__ a) { - unsigned int t = a + 100u; - unsigned long w = (unsigned long) a + 100; - return w == (unsigned long) t; + __UINT32_TYPE__ t = a + 100u; + __UINT64_TYPE__ w = (__UINT64_TYPE__) a + 100; + return w == (__UINT64_TYPE__) t; } /* Legitimate in-range case (matches the PR): k == j - 1, so the two