Several blocks of longlong.h do not build with clang, because clang
rejects casts on asm output operands. This affects libgcrypt, which
imports longlong.h, and wide-int.cc in GCC itself.

 1. Remove the Z8000 block, as Richard suggested. Unchanged from v2.

 2. Update the header comment, which still says the file is part of
    the GNU C Library. glibc removed its copy of longlong.h in 2.43.

 3. Wrap each output cast in a macro, as Jakub suggested:

        : "=r" __ll_check_output (USItype, sh),

 4. Let wide-int.cc include longlong.h under clang again, so a GCC
    built by clang without bootstrapping uses umul_ppmm.

With GCC, patch 3 expands to the same casts as before. With clang, the
i386 block, the x86_64 and sparc64 blocks for W_TYPE_SIZE 64, and the
arm blocks as C now build. The arm blocks still fail as C++, because
the arm umul_ppmm declares a register variable, which C++17 does not
allow; that is a separate problem.

Tested by building x86_64-pc-linux-gnu with clang 22 as the host
compiler (--disable-bootstrap). wi::mul_internal now uses mulq, the
selftests pass and the target libraries build.

Changes in v3:
- Replace the sizeof check with __ll_check_output, which keeps the cast
  for GCC and drops it for clang (Jakub). GCC's cast check rejects
  any conversion that is not a no-op, while the size check accepted
  outputs of a different type with the same size.
- Drop v2 patches 3 and 4 (__ll_out and the libquadmath register
  change). They are no longer needed since GCC keeps the cast.
- New patch 2: say longlong.h is part of GCC, not the GNU C Library,
  and update the stale comment on attribute_hidden.
- New patch 4: include longlong.h in wide-int.cc with clang.
- Link to v2: 
https://inbox.sourceware.org/gcc-patches/[email protected]/

Changes in v2:
- Keep the output size check instead of dropping it (patch 2).
- Remove the Z8000 block instead of editing it (patch 1).
- New, optional: patches 3 and 4.
- v1 patch 2/2 (sdiv_qrnnd parentheses) is already committed.
- Link to v1: 
https://inbox.sourceware.org/gcc-patches/[email protected]/

---
Matt Turner (4):
      include: Remove Z8000 support from longlong.h
      include: Say longlong.h is part of GCC, not the GNU C Library
      include: Wrap the casts on asm output operands in longlong.h in a macro
      wide-int.cc: Include longlong.h when built with clang [PR61146]

 gcc/wide-int.cc    |   3 +-
 include/longlong.h | 241 ++++++++++++++++++++++++-----------------------------
 2 files changed, 110 insertions(+), 134 deletions(-)
---
base-commit: e47eccbe6d118023e4fe83bde14075729c40e030
change-id: 20260921-longlong-fixes-v2-d8f7bb2376cc

Best regards,
-- 
Matt Turner <[email protected]>

Reply via email to