https://github.com/pkubaj updated https://github.com/llvm/llvm-project/pull/201298
>From 263b6c8efb7093df768c08e03624b0df94830cdc Mon Sep 17 00:00:00 2001 From: Piotr Kubaj <[email protected]> Date: Wed, 3 Jun 2026 11:12:14 +0200 Subject: [PATCH] [clang][PowerPC] Enable IEEE-128 long double on FreeBSD/powerpc64le Starting with FreeBSD 16, powerpc64le switches its long double type from 64-bit double to IEEE 754 binary128, matching the GCC powerpc64le ABI and the IEEE-128 long double already used on aarch64 and riscv. For the FreeBSD powerpc64le triple with an OS major version >= 16: - In PPC64TargetInfo, set the long double width and alignment to 128 and the format to IEEEquad, instead of falling into the 64-bit double case shared with OpenBSD and musl. - ToolChain::defaultToIEEELongDouble() returns true, so the driver selects IEEE-128 long double independently of the Linux-only PPC_LINUX_DEFAULT_IEEELONGDOUBLE setting. Also restrict the F128Builtins redirection (printf/scanf/*_chk -> __*ieee128) to GNU environments. The *ieee128-suffixed names are glibc's mechanism for coexisting IBM double-double and IEEE-128 long double in a single library; targets with a single IEEE-128 long double format, such as FreeBSD, use the unsuffixed libm names, which is what the backend already emits. --- clang/lib/Basic/Targets/PPC.h | 7 ++++++- clang/lib/CodeGen/CGBuiltin.cpp | 5 ++++- clang/lib/Driver/ToolChain.cpp | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h index a9f49aa3aebe1..211590eae32c7 100644 --- a/clang/lib/Basic/Targets/PPC.h +++ b/clang/lib/Basic/Targets/PPC.h @@ -457,7 +457,12 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo { ABI = "elfv1"; } - if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) { + if (Triple.isOSFreeBSD() && Triple.getArch() == llvm::Triple::ppc64le && + Triple.getOSMajorVersion() >= 16) { + LongDoubleWidth = LongDoubleAlign = 128; + LongDoubleFormat = &llvm::APFloat::IEEEquad(); + } else if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || + Triple.isMusl()) { LongDoubleWidth = LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEdouble(); } diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3f0322e5878c7..2187096bed3b3 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -232,7 +232,10 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, else { // TODO: This mutation should also be applied to other targets other than // PPC, after backend supports IEEE 128-bit style libcalls. - if (getTriple().isPPC64() && + // The *ieee128 names are glibc's mechanism for coexisting IBM double-double + // and IEEE-128 long double in one library; targets with a single IEEE-128 + // long double format (e.g. FreeBSD) use the unsuffixed names. + if (getTriple().isPPC64() && getTriple().isGNUEnvironment() && &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() && F128Builtins.contains(BuiltinID)) Name = F128Builtins.lookup(BuiltinID); diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 511eb3757456b..32faf3dbe3769 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -263,6 +263,10 @@ bool ToolChain::useRelaxRelocations() const { } bool ToolChain::defaultToIEEELongDouble() const { + if (getTriple().isOSFreeBSD() && + getTriple().getArch() == llvm::Triple::ppc64le && + getTriple().getOSMajorVersion() >= 16) + return true; return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux(); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
