]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: Yet another fix for _BitInt & __sync_* builtins [PR117641]
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Nov 2024 18:47:52 +0000 (19:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Nov 2024 18:47:52 +0000 (19:47 +0100)
Sorry, the last patch only partially fixed the __sync_* ICEs with
_BitInt(128) on ia32.
Even for !fetch we need to error out and return 0.  I was afraid of
APIs like __atomic_exchange/__atomic_compare_exchange, those obviously
need to be supported even on _BitInt(128) on ia32, but they actually never
sync_resolve_size, they are handled by adding the size argument and using
the library version much earlier.
For fetch && !orig_format (i.e. __atomic_fetch_* etc.) we need to return -1
so that we handle it with a manualy __atomic_load +
__atomic_compare_exchange loop in the caller, all other cases should
be rejected.

2024-11-22  Jakub Jelinek  <jakub@redhat.com>

PR c/117641
* c-common.cc (sync_resolve_size): For size 16 with _BitInt
on targets where TImode isn't supported, use goto incompatible if
!fetch.

* gcc.dg/bitint-117.c: New test.

gcc/c-family/c-common.cc
gcc/testsuite/gcc.dg/bitint-117.c [new file with mode: 0644]

index 367a9b07c872386715d9d89bddaf0d4ed63922ad..9254fb6c010a26e6ed9d6e2ec11c976f7eb31b67 100644 (file)
@@ -7457,11 +7457,10 @@ sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch,
 
   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
   if (size == 16
-      && fetch
       && TREE_CODE (type) == BITINT_TYPE
       && !targetm.scalar_mode_supported_p (TImode))
     {
-      if (!orig_format)
+      if (fetch && !orig_format)
        return -1;
       goto incompatible;
     }
diff --git a/gcc/testsuite/gcc.dg/bitint-117.c b/gcc/testsuite/gcc.dg/bitint-117.c
new file mode 100644 (file)
index 0000000..16a7616
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c/117641 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-std=c23" } */
+
+void
+foo (_BitInt(128) *b)
+{
+  __sync_add_and_fetch (b, 1);                 /* { dg-error "incompatible" "" { target { ! int128 } } } */
+  __sync_val_compare_and_swap (b, 0, 1);       /* { dg-error "incompatible" "" { target { ! int128 } } } */
+  __sync_bool_compare_and_swap (b, 0, 1);      /* { dg-error "incompatible" "" { target { ! int128 } } } */
+  __sync_lock_test_and_set (b, 1);             /* { dg-error "incompatible" "" { target { ! int128 } } } */
+  __sync_lock_release (b);                     /* { dg-error "incompatible" "" { target { ! int128 } } } */
+}