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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:6d0503f87898617756bd423b3fe9d14b2d4e76c6

commit r14-11141-g6d0503f87898617756bd423b3fe9d14b2d4e76c6
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Nov 19 20:36:00 2024 +0100

    c-family: Fix ICE with __sync_*_and_* on _BitInt [PR117641]

    Only __atomic_* builtins are meant to work on arbitrary _BitInt types
    (if not supported in hw we emit a CAS loop which uses __atomic_load_*
    in that case), the compatibility __sync_* builtins work only if there
    is a corresponding normal integral type (for _BitInt on 32-bit ARM
    we'll need to limit even that to no padding, because the padding bits
    are well defined there and the hw or libatomic __sync_* APIs don't
    guarantee that), IMHO people shouldn't mix very old APIs with very
    new ones and I don't see a replacement for the __atomic_load_*.

    For size > 16 that is how it already correctly behaves,
    in the hunk shown in the patch it is immediately followed by

      if (fetch && !orig_format && TREE_CODE (type) == BITINT_TYPE)
        return -1;

    which returns -1 for the __atomic_* builtins (i.e. !orig_format),
    which causes caller to use atomic_bitint_fetch_using_cas_loop,
    and otherwise does diagnostic and return 0 (which causes caller
    to punt).  But for size == 16 if TImode isn't suipported (i.e.
    mostly 32-bit arches), we return (correctly) -1 if !orig_format,
    so again force atomic_bitint_fetch_using_cas_loop on those arches
    for e.g. _BitInt(115), but for orig_format the function returns
    16 as if it could do 16 byte __sync_*_and_* (which it can't
    because TImode isn't supported; for 16 byte it can only do
    (perhaps using libatomic) normal compare and swap).  So we need
    to error and return 0, rather than return 16.

    The following patch ensures that.

    2024-11-19  Jakub Jelinek  <ja...@redhat.com>

            PR c/117641
            * c-common.cc (sync_resolve_size): For size == 16 fetch of
            BITINT_TYPE if TImode isn't supported scalar mode diagnose
            and return 0 if orig_format instead of returning 16.

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

    (cherry picked from commit 8663fc1c2826c86455e51e58203cb95b2b1407e3)

Reply via email to