https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117641

--- Comment #5 from Zdenek Sojka <zsojka at seznam dot cz> ---
(In reply to Jakub Jelinek from comment #3)
> Created attachment 59622 [details]
> gcc15-pr117641.patch
> 
> Untested fix (which will just error out in this case).
> The __sync_fetch* etc. compatibility builtins aren't really meant to be used
> with _BitInt, the __atomic_* builtins are, for a good reason - to emulate it
> it needs to use also atomic loads/stores and there aren't any for __sync_*.

Thank you for the fix; I am still observing the same issue with
__sync_lock_test_and_set(), __sync_*_compare_and_swap().
Not with __sync_lock_release(), but that's probably due to PR117642, as it
doesn't generate any code.

$ cat testcase.c
void
foo(_BitInt(128) *b)
{
  __sync_fetch_and_add(b, 1);
  __sync_add_and_fetch(b, 1);
  __sync_val_compare_and_swap(b, 0, 1);
  __sync_bool_compare_and_swap(b, 0, 1);
  __sync_lock_test_and_set(b, 1);
  __sync_lock_release(b);
}
$ x86_64-pc-linux-gnu-gcc -m32 testcase.c
testcase.c: In function 'foo':
testcase.c:4:3: error: operand type '_BitInt(128) *' is incompatible with
argument 1 of '__sync_fetch_and_add'
    4 |   __sync_fetch_and_add(b, 1);
      |   ^~~~~~~~~~~~~~~~~~~~
testcase.c:5:3: error: operand type '_BitInt(128) *' is incompatible with
argument 1 of '__sync_add_and_fetch'
    5 |   __sync_add_and_fetch(b, 1);
      |   ^~~~~~~~~~~~~~~~~~~~
testcase.c:6:3: internal compiler error: Segmentation fault
    6 |   __sync_val_compare_and_swap(b, 0, 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
0x2cc8aae internal_error(char const*, ...)
        /repo/gcc-trunk/gcc/diagnostic-global-context.cc:518
0x15d822f crash_signal
        /repo/gcc-trunk/gcc/toplev.cc:323
0xf83ed8 contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        /repo/gcc-trunk/gcc/tree.h:3788
...

This is with r15-5474.

Reply via email to