diff mbox series

c: Add u{,l,ll,imax}abs builtins [PR117024]

Message ID Zw/fRWKefkMF0bYO@tucnak
State New
Headers show
Series c: Add u{,l,ll,imax}abs builtins [PR117024] | expand

Commit Message

Jakub Jelinek Oct. 16, 2024, 3:44 p.m. UTC
Hi!

The following patch adds u{,l,ll,imax}abs builtins, which just fold
to ABSU_EXPR, similarly to how {,l,ll,imax}abs builtins fold to
ABS_EXPR.

Tested on x86_64-linux, ok for trunk if it passes full bootstrap/regtest
on x86_64-linux and i686-linux?

2024-10-16  Jakub Jelinek  <jakub@redhat.com>

	PR c/117024
gcc/
	* coretypes.h (enum function_class): Add function_c2y_misc
	enumerator.
	* builtin-types.def (BT_FN_UINTMAX_INTMAX, BT_FN_ULONG_LONG,
	BT_FN_ULONGLONG_LONGLONG): New DEF_FUNCTION_TYPE_1s.
	* builtins.def (DEF_C2Y_BUILTIN): Define.
	(BUILT_IN_UABS, BUILT_IN_UIMAXABS, BUILT_IN_ULABS,
	BUILT_IN_ULLABS): New builtins.
	* builtins.cc (fold_builtin_abs): Handle also folding of u*abs
	to ABSU_EXPR.
	(fold_builtin_1): Handle BUILT_IN_U{,L,LL,IMAX}ABS.
gcc/lto/ChangeLog:
	* lto-lang.cc (flag_isoc2y): New variable.
gcc/ada/ChangeLog:
	* gcc-interface/utils.cc (flag_isoc2y): New variable.
gcc/testsuite/
	* gcc.c-torture/execute/builtins/lib/abs.c (uintmax_t): New typedef.
	(uabs, ulabs, ullabs, uimaxabs): New functions.
	* gcc.c-torture/execute/builtins/uabs-1.c: New test.
	* gcc.c-torture/execute/builtins/uabs-1.x: New file.
	* gcc.c-torture/execute/builtins/uabs-1-lib.c: New file.
	* gcc.c-torture/execute/builtins/uabs-2.c: New test.
	* gcc.c-torture/execute/builtins/uabs-2.x: New file.
	* gcc.c-torture/execute/builtins/uabs-2-lib.c: New file.
	* gcc.c-torture/execute/builtins/uabs-3.c: New test.
	* gcc.c-torture/execute/builtins/uabs-3.x: New test.
	* gcc.c-torture/execute/builtins/uabs-3-lib.c: New test.


	Jakub
diff mbox series

Patch

--- gcc/coretypes.h.jj	2024-09-24 11:31:48.672622744 +0200
+++ gcc/coretypes.h	2024-10-16 16:05:51.329632572 +0200
@@ -421,7 +421,8 @@  enum function_class {
   function_c99_math_complex,
   function_sincos,
   function_c11_misc,
-  function_c23_misc
+  function_c23_misc,
+  function_c2y_misc
 };
 
 /* Enumerate visibility settings.  This is deliberately ordered from most
--- gcc/builtin-types.def.jj	2024-01-03 11:51:37.930642379 +0100
+++ gcc/builtin-types.def	2024-10-16 16:17:42.424573438 +0200
@@ -252,6 +252,7 @@  DEF_FUNCTION_TYPE_0 (BT_FN_DFLOAT128, BT
 
 DEF_FUNCTION_TYPE_1 (BT_FN_LONG_LONG, BT_LONG, BT_LONG)
 DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_LONGLONG, BT_LONGLONG, BT_LONGLONG)
+DEF_FUNCTION_TYPE_1 (BT_FN_UINTMAX_INTMAX, BT_UINTMAX, BT_INTMAX)
 DEF_FUNCTION_TYPE_1 (BT_FN_INTMAX_INTMAX, BT_INTMAX, BT_INTMAX)
 DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT_FLOAT, BT_FLOAT, BT_FLOAT)
 DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_DOUBLE, BT_DOUBLE, BT_DOUBLE)
@@ -396,7 +397,9 @@  DEF_FUNCTION_TYPE_1 (BT_FN_UINT_CONST_PT
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_PTR, BT_ULONG, BT_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_CONST_PTR, BT_ULONG, BT_CONST_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_ULONG, BT_ULONG, BT_ULONG)
+DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_LONG, BT_ULONG, BT_LONG)
 DEF_FUNCTION_TYPE_1 (BT_FN_ULONGLONG_ULONGLONG, BT_ULONGLONG, BT_ULONGLONG)
+DEF_FUNCTION_TYPE_1 (BT_FN_ULONGLONG_LONGLONG, BT_ULONGLONG, BT_LONGLONG)
 DEF_FUNCTION_TYPE_1 (BT_FN_INT8_FLOAT, BT_INT8, BT_FLOAT)
 DEF_FUNCTION_TYPE_1 (BT_FN_INT16_FLOAT, BT_INT16, BT_FLOAT)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_FLOAT, BT_UINT32, BT_FLOAT)
--- gcc/builtins.def.jj	2024-08-12 10:49:12.043616424 +0200
+++ gcc/builtins.def	2024-10-16 16:34:26.228365799 +0200
@@ -164,6 +164,14 @@  along with GCC; see the file COPYING3.
 	       true, true, !flag_isoc23, ATTRS, \
 	       targetm.libc_has_function (function_c23_misc, NULL_TREE), true)
 
+/* Like DEF_LIB_BUILTIN, except that the function is only a part of
+   the standard in C2Y or above.  */
+#undef DEF_C2Y_BUILTIN
+#define DEF_C2Y_BUILTIN(ENUM, NAME, TYPE, ATTRS)	\
+  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,	\
+	       true, true, !flag_isoc2y, ATTRS, \
+	       targetm.libc_has_function (function_c2y_misc, NULL_TREE), true)
+
 /* Like DEF_C99_BUILTIN, but for complex math functions.  */
 #undef DEF_C99_COMPL_BUILTIN
 #define DEF_C99_COMPL_BUILTIN(ENUM, NAME, TYPE, ATTRS)	\
@@ -1069,6 +1077,10 @@  DEF_GCC_BUILTIN        (BUILT_IN_SETJMP,
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRFMON, "strfmon", BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_NOTHROW_3_4)
 DEF_LIB_BUILTIN        (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_TM_PTR, ATTR_FORMAT_STRFTIME_NOTHROW_3_0)
 DEF_GCC_BUILTIN        (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST)
+DEF_C2Y_BUILTIN        (BUILT_IN_UABS, "uabs", BT_FN_UINT_INT, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_C2Y_BUILTIN        (BUILT_IN_UIMAXABS, "uimaxabs", BT_FN_UINTMAX_INTMAX, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_C2Y_BUILTIN        (BUILT_IN_ULABS, "ulabs", BT_FN_ULONG_LONG, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_C2Y_BUILTIN        (BUILT_IN_ULLABS, "ullabs", BT_FN_ULONGLONG_LONGLONG, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_UNREACHABLE_TRAP, "unreachable trap", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_UNREACHABLE, "unreachable", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_UNWIND_INIT, "unwind_init", BT_FN_VOID, ATTR_NULL)
--- gcc/builtins.cc.jj	2024-08-30 16:41:34.641368091 +0200
+++ gcc/builtins.cc	2024-10-16 16:55:16.370684438 +0200
@@ -9377,7 +9377,8 @@  fold_builtin_fabs (location_t loc, tree
   return fold_build1_loc (loc, ABS_EXPR, type, arg);
 }
 
-/* Fold a call to abs, labs, llabs or imaxabs with argument ARG.  */
+/* Fold a call to abs, labs, llabs, imaxabs, uabs, ulabs, ullabs or uimaxabs
+   with argument ARG.  */
 
 static tree
 fold_builtin_abs (location_t loc, tree arg, tree type)
@@ -9385,6 +9386,14 @@  fold_builtin_abs (location_t loc, tree a
   if (!validate_arg (arg, INTEGER_TYPE))
     return NULL_TREE;
 
+  if (TYPE_UNSIGNED (type))
+    {
+      if (TYPE_PRECISION (TREE_TYPE (arg))
+	  != TYPE_PRECISION (type)
+	  || TYPE_UNSIGNED (TREE_TYPE (arg)))
+	return NULL_TREE;
+      return fold_build1_loc (loc, ABSU_EXPR, type, arg);
+    }
   arg = fold_convert_loc (loc, type, arg);
   return fold_build1_loc (loc, ABS_EXPR, type, arg);
 }
@@ -10515,6 +10524,10 @@  fold_builtin_1 (location_t loc, tree exp
     case BUILT_IN_LABS:
     case BUILT_IN_LLABS:
     case BUILT_IN_IMAXABS:
+    case BUILT_IN_UABS:
+    case BUILT_IN_ULABS:
+    case BUILT_IN_ULLABS:
+    case BUILT_IN_UIMAXABS:
       return fold_builtin_abs (loc, arg0, type);
 
     CASE_FLT_FN (BUILT_IN_CONJ):
--- gcc/lto/lto-lang.cc.jj	2024-01-03 12:07:08.082651331 +0100
+++ gcc/lto/lto-lang.cc	2024-10-16 16:46:25.224187423 +0200
@@ -262,6 +262,7 @@  int flag_isoc94;
 int flag_isoc99;
 int flag_isoc11;
 int flag_isoc23;
+int flag_isoc2y;
 
 /* Attribute handlers.  */
 
--- gcc/ada/gcc-interface/utils.cc.jj	2024-10-07 11:37:46.214982575 +0200
+++ gcc/ada/gcc-interface/utils.cc	2024-10-16 16:46:46.935880722 +0200
@@ -7501,6 +7501,7 @@  static int flag_isoc94 = 0;
 static int flag_isoc99 = 0;
 static int flag_isoc11 = 0;
 static int flag_isoc23 = 0;
+static int flag_isoc2y = 0;
 
 /* Install what the common builtins.def offers plus our local additions.
 
--- gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c.jj	2022-01-05 20:30:08.852805055 +0100
+++ gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c	2024-10-16 16:57:52.417480117 +0200
@@ -7,6 +7,7 @@  extern void abort (void);
 #endif
 
 typedef __INTMAX_TYPE__ intmax_t;
+typedef unsigned __INTMAX_TYPE__ uintmax_t;
 
 __attribute__ ((__noinline__))
 int
@@ -39,3 +40,35 @@  imaxabs (intmax_t x)
   ABORT_INSIDE_MAIN;
   return x < 0 ? -x : x;
 }
+
+__attribute__ ((__noinline__))
+unsigned int
+uabs (int x)
+{
+  ABORT_INSIDE_MAIN;
+  return x < 0 ? -(unsigned int) x : x;
+}
+
+__attribute__ ((__noinline__))
+unsigned long
+ulabs (long x)
+{
+  ABORT_INSIDE_MAIN;
+  return x < 0 ? -(unsigned long) x : x;
+}
+
+__attribute__ ((__noinline__))
+unsigned long long
+ullabs (long long x)
+{
+  ABORT_INSIDE_MAIN;
+  return x < 0 ? -(unsigned long long) x : x;
+}
+
+__attribute__ ((__noinline__))
+uintmax_t
+uimaxabs (intmax_t x)
+{
+  ABORT_INSIDE_MAIN;
+  return x < 0 ? -(uintmax_t) x : x;
+}
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1.c.jj	2024-10-16 17:00:20.934382165 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1.c	2024-10-16 17:02:15.676760678 +0200
@@ -0,0 +1,22 @@ 
+/* Test for -fno-builtin-FUNCTION.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk>.  */
+/* GCC normally handles uabs and ulabs as built-in functions even without
+   optimization.  So test that with -fno-builtin-uabs, ulabs is so handled
+   but uabs isn't.  */
+
+int abs_called = 0;
+
+extern unsigned int uabs (int);
+extern unsigned long ulabs (long);
+extern void abort (void);
+
+void
+main_test (void)
+{
+  if (ulabs (0) != 0)
+    abort ();
+  if (uabs (0) != 0)
+    abort ();
+  if (!abs_called)
+    abort ();
+}
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1.x.jj	2024-10-16 17:00:33.690201975 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1.x	2024-10-16 17:31:21.911093413 +0200
@@ -0,0 +1,2 @@ 
+set additional_flags "-fno-builtin-uabs -std=c2y"
+return 0
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1-lib.c.jj	2024-10-16 17:00:17.249434221 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-1-lib.c	2024-10-16 17:01:34.568341968 +0200
@@ -0,0 +1,22 @@ 
+extern void abort (void);
+extern int abs_called;
+extern int inside_main;
+
+/* The ulabs call should have been optimized, but the uabs call
+   shouldn't have been.  */
+
+unsigned int
+uabs (int x)
+{
+  if (inside_main)
+    abs_called = 1;
+  return (x < 0 ? -(unsigned int) x : x);
+}
+
+unsigned long
+ulabs (long x)
+{
+  if (inside_main)
+    abort ();
+  return (x < 0 ? -(unsigned long) x : x);
+}
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2.c.jj	2024-10-16 17:00:42.168082210 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2.c	2024-10-16 17:18:14.470203032 +0200
@@ -0,0 +1,123 @@ 
+/* Test for builtin uabs, ulabs, ullabs, uimaxabs.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+
+#include <limits.h>
+typedef __INTMAX_TYPE__ intmax_t;
+typedef unsigned __INTMAX_TYPE__ uintmax_t;
+#define INTMAX_MAX __INTMAX_MAX__
+
+extern unsigned int uabs (int);
+extern unsigned long ulabs (long);
+extern unsigned long long ullabs (long long);
+extern uintmax_t uimaxabs (intmax_t);
+extern void abort (void);
+extern void link_error (void);
+
+void
+main_test (void)
+{
+  /* For each type, test both runtime and compile time (constant folding)
+     optimization.  */
+  volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX;
+  volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX;
+  volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL;
+  volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__;
+  volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1;
+  volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX;
+  if (uabs (i0) != 0)
+    abort ();
+  if (uabs (0) != 0)
+    link_error ();
+  if (uabs (i1) != 1)
+    abort ();
+  if (uabs (1) != 1)
+    link_error ();
+  if (uabs (im1) != 1)
+    abort ();
+  if (uabs (-1) != 1)
+    link_error ();
+  if (uabs (imin) != INT_MAX)
+    abort ();
+  if (uabs (imin - 1) != 1U + INT_MAX)
+    abort ();
+  if (uabs (-INT_MAX) != INT_MAX)
+    link_error ();
+  if (uabs (-INT_MAX - 1) != 1U + INT_MAX)
+    link_error ();
+  if (uabs (imax) != INT_MAX)
+    abort ();
+  if (uabs (INT_MAX) != INT_MAX)
+    link_error ();
+  if (ulabs (l0) != 0L)
+    abort ();
+  if (ulabs (0L) != 0L)
+    link_error ();
+  if (ulabs (l1) != 1L)
+    abort ();
+  if (ulabs (1L) != 1L)
+    link_error ();
+  if (ulabs (lm1) != 1L)
+    abort ();
+  if (ulabs (-1L) != 1L)
+    link_error ();
+  if (ulabs (lmin) != LONG_MAX)
+    abort ();
+  if (ulabs (lmin - 1) != 1UL + LONG_MAX)
+    abort ();
+  if (ulabs (-LONG_MAX) != LONG_MAX)
+    link_error ();
+  if (ulabs (-LONG_MAX - 1) != 1UL + LONG_MAX)
+    link_error ();
+  if (ulabs (lmax) != LONG_MAX)
+    abort ();
+  if (ulabs (LONG_MAX) != LONG_MAX)
+    link_error ();
+  if (ullabs (ll0) != 0LL)
+    abort ();
+  if (ullabs (0LL) != 0LL)
+    link_error ();
+  if (ullabs (ll1) != 1LL)
+    abort ();
+  if (ullabs (1LL) != 1LL)
+    link_error ();
+  if (ullabs (llm1) != 1LL)
+    abort ();
+  if (ullabs (-1LL) != 1LL)
+    link_error ();
+  if (ullabs (llmin) != __LONG_LONG_MAX__)
+    abort ();
+  if (ullabs (llmin - 1) != 1ULL + __LONG_LONG_MAX__)
+    abort ();
+  if (ullabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
+    link_error ();
+  if (ullabs (-__LONG_LONG_MAX__ - 1) != 1ULL + __LONG_LONG_MAX__)
+    link_error ();
+  if (ullabs (llmax) != __LONG_LONG_MAX__)
+    abort ();
+  if (ullabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
+    link_error ();
+  if (uimaxabs (imax0) != 0)
+    abort ();
+  if (uimaxabs (0) != 0)
+    link_error ();
+  if (uimaxabs (imax1) != 1)
+    abort ();
+  if (uimaxabs (1) != 1)
+    link_error ();
+  if (uimaxabs (imaxm1) != 1)
+    abort ();
+  if (uimaxabs (-1) != 1)
+    link_error ();
+  if (uimaxabs (imaxmin) != INTMAX_MAX)
+    abort ();
+  if (uimaxabs (imaxmin - 1) != (uintmax_t) 1 + INTMAX_MAX)
+    abort ();
+  if (uimaxabs (-INTMAX_MAX) != INTMAX_MAX)
+    link_error ();
+  if (uimaxabs (-INTMAX_MAX - 1) != (uintmax_t) 1 + INTMAX_MAX)
+    link_error ();
+  if (uimaxabs (imaxmax) != INTMAX_MAX)
+    abort ();
+  if (uimaxabs (INTMAX_MAX) != INTMAX_MAX)
+    link_error ();
+}
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2.x.jj	2024-10-16 17:19:05.061487962 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2.x	2024-10-16 17:19:11.045403548 +0200
@@ -0,0 +1,2 @@ 
+set additional_flags -std=c2y
+return 0
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2-lib.c.jj	2024-10-16 17:00:38.873128764 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-2-lib.c	2020-01-11 16:31:55.021293706 +0100
@@ -0,0 +1 @@ 
+#include "lib/abs.c"
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3.c.jj	2024-10-16 17:00:51.438951253 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3.c	2024-10-16 17:22:55.868232030 +0200
@@ -0,0 +1,119 @@ 
+/* Test for builtin uabs, ulabs, ullabs, uimaxabs.  Test for __builtin versions. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+
+#include <limits.h>
+typedef __INTMAX_TYPE__ intmax_t;
+typedef unsigned __INTMAX_TYPE__ uintmax_t;
+#define INTMAX_MAX __INTMAX_MAX__
+
+extern void abort (void);
+extern void link_error (void);
+
+void
+main_test (void)
+{
+  /* For each type, test both runtime and compile time (constant folding)
+     optimization.  */
+  volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX;
+  volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX;
+  volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL;
+  volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__;
+  volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1;
+  volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX;
+  if (__builtin_uabs (i0) != 0)
+    abort ();
+  if (__builtin_uabs (0) != 0)
+    link_error ();
+  if (__builtin_uabs (i1) != 1)
+    abort ();
+  if (__builtin_uabs (1) != 1)
+    link_error ();
+  if (__builtin_uabs (im1) != 1)
+    abort ();
+  if (__builtin_uabs (-1) != 1)
+    link_error ();
+  if (__builtin_uabs (imin) != INT_MAX)
+    abort ();
+  if (__builtin_uabs (imin - 1) != 1U + INT_MAX)
+    abort ();
+  if (__builtin_uabs (-INT_MAX) != INT_MAX)
+    link_error ();
+  if (__builtin_uabs (-INT_MAX - 1) != 1U + INT_MAX)
+    link_error ();
+  if (__builtin_uabs (imax) != INT_MAX)
+    abort ();
+  if (__builtin_uabs (INT_MAX) != INT_MAX)
+    link_error ();
+  if (__builtin_ulabs (l0) != 0L)
+    abort ();
+  if (__builtin_ulabs (0L) != 0L)
+    link_error ();
+  if (__builtin_ulabs (l1) != 1L)
+    abort ();
+  if (__builtin_ulabs (1L) != 1L)
+    link_error ();
+  if (__builtin_ulabs (lm1) != 1L)
+    abort ();
+  if (__builtin_ulabs (-1L) != 1L)
+    link_error ();
+  if (__builtin_ulabs (lmin) != LONG_MAX)
+    abort ();
+  if (__builtin_ulabs (lmin - 1) != 1UL + LONG_MAX)
+    abort ();
+  if (__builtin_ulabs (-LONG_MAX) != LONG_MAX)
+    link_error ();
+  if (__builtin_ulabs (-LONG_MAX - 1) != 1UL + LONG_MAX)
+    link_error ();
+  if (__builtin_ulabs (lmax) != LONG_MAX)
+    abort ();
+  if (__builtin_ulabs (LONG_MAX) != LONG_MAX)
+    link_error ();
+  if (__builtin_ullabs (ll0) != 0LL)
+    abort ();
+  if (__builtin_ullabs (0LL) != 0LL)
+    link_error ();
+  if (__builtin_ullabs (ll1) != 1LL)
+    abort ();
+  if (__builtin_ullabs (1LL) != 1LL)
+    link_error ();
+  if (__builtin_ullabs (llm1) != 1LL)
+    abort ();
+  if (__builtin_ullabs (-1LL) != 1LL)
+    link_error ();
+  if (__builtin_ullabs (llmin) != __LONG_LONG_MAX__)
+    abort ();
+  if (__builtin_ullabs (llmin - 1) != 1ULL + __LONG_LONG_MAX__)
+    abort ();
+  if (__builtin_ullabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
+    link_error ();
+  if (__builtin_ullabs (-__LONG_LONG_MAX__ - 1) != 1ULL + __LONG_LONG_MAX__)
+    link_error ();
+  if (__builtin_ullabs (llmax) != __LONG_LONG_MAX__)
+    abort ();
+  if (__builtin_ullabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
+    link_error ();
+  if (__builtin_uimaxabs (imax0) != 0)
+    abort ();
+  if (__builtin_uimaxabs (0) != 0)
+    link_error ();
+  if (__builtin_uimaxabs (imax1) != 1)
+    abort ();
+  if (__builtin_uimaxabs (1) != 1)
+    link_error ();
+  if (__builtin_uimaxabs (imaxm1) != 1)
+    abort ();
+  if (__builtin_uimaxabs (-1) != 1)
+    link_error ();
+  if (__builtin_uimaxabs (imaxmin) != INTMAX_MAX)
+    abort ();
+  if (__builtin_uimaxabs (imaxmin - 1) != (uintmax_t) 1 + INTMAX_MAX)
+    abort ();
+  if (__builtin_uimaxabs (-INTMAX_MAX) != INTMAX_MAX)
+    link_error ();
+  if (__builtin_uimaxabs (-INTMAX_MAX - 1) != (uintmax_t) 1 + INTMAX_MAX)
+    link_error ();
+  if (__builtin_uimaxabs (imaxmax) != INTMAX_MAX)
+    abort ();
+  if (__builtin_uimaxabs (INTMAX_MAX) != INTMAX_MAX)
+    link_error ();
+}
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3.x.jj	2024-10-16 17:19:20.744266730 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3.x	2024-10-16 17:19:11.045403548 +0200
@@ -0,0 +1,2 @@ 
+set additional_flags -std=c2y
+return 0
--- gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3-lib.c.jj	2024-10-16 17:00:48.059998986 +0200
+++ gcc/testsuite/gcc.c-torture/execute/builtins/uabs-3-lib.c	2020-01-11 16:31:55.021293706 +0100
@@ -0,0 +1 @@ 
+#include "lib/abs.c"