]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/124545 - fix pr124545-2.c on ilp32 targets
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Fri, 3 Jul 2026 18:16:38 +0000 (20:16 +0200)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Mon, 6 Jul 2026 21:38:34 +0000 (23:38 +0200)
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 <torbjorn.svensson@foss.st.com>
Tested-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
gcc/testsuite/gcc.dg/pr124545-2.c

index b4806567accecc546831d046d267e7e447d2beb7..990f509d3490f615b521c15f10b956661840fa24 100644 (file)
@@ -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" } */
 
 __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