https://github.com/jofrn created https://github.com/llvm/llvm-project/pull/205016
A full build replaces the system (Apple) <fenv.h> with libc's headers, so fenv_darwin_impl.h no longer found an 8-byte fenv_t, FE_FLUSHTOZERO, or the __fpcr_* masks it relied on. Size FPState to the fenv_t in scope, alias FE_FLUSHTOZERO to FE_DENORM, and define the FPCR trap masks locally. Stacked on https://github.com/llvm/llvm-project/pull/204981. >From 4b1bdcd2393f3f4ce8a7a3366c336e9cad3a0e57 Mon Sep 17 00:00:00 2001 From: jofrn <[email protected]> Date: Sat, 20 Jun 2026 23:52:22 -0700 Subject: [PATCH] [libc][math] Fix aarch64 Darwin fenv implementation for full builds A full build replaces the system (Apple) <fenv.h> with libc's headers, so fenv_darwin_impl.h no longer found an 8-byte fenv_t, FE_FLUSHTOZERO, or the __fpcr_* masks it relied on. Size FPState to the fenv_t in scope, alias FE_FLUSHTOZERO to FE_DENORM, and define the FPCR trap masks locally. --- .../FPUtil/aarch64/fenv_darwin_impl.h | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h index a2066d1025f63..595955518f90e 100644 --- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h +++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h @@ -24,13 +24,28 @@ #include "hdr/types/fenv_t.h" #include "src/__support/FPUtil/FPBits.h" +// libc's <fenv.h> spells the denormal/flush-to-zero exception FE_DENORM, while +// the system (Apple) <fenv.h> used in an overlay build spells it FE_FLUSHTOZERO. +// Provide the latter as an alias in a full build so the code below uses a single +// name. +#ifndef FE_FLUSHTOZERO +#define FE_FLUSHTOZERO FE_DENORM +#endif + namespace LIBC_NAMESPACE_DECL { namespace fputil { struct FEnv { struct FPState { +#ifdef LIBC_FULL_BUILD + // libc's own fenv_t: a 4-byte status word and a 4-byte control word. + uint32_t StatusWord; + uint32_t ControlWord; +#else + // The system (Apple) fenv_t in an overlay build: two 64-bit words. uint64_t StatusWord; uint64_t ControlWord; +#endif }; static_assert( @@ -55,6 +70,18 @@ struct FEnv { // to zero. static constexpr uint32_t EX_FLUSHTOZERO = 0x20; + // FPCR trap-enable bit masks. These come from Apple's <fenv.h> (not the ACLE + // <arm_acle.h>), which a full build replaces with libc's own fenv headers, so + // define them here with the same values Apple uses. +#ifdef LIBC_FULL_BUILD + static constexpr uint32_t __fpcr_trap_invalid = 0x00000100; + static constexpr uint32_t __fpcr_trap_divbyzero = 0x00000200; + static constexpr uint32_t __fpcr_trap_overflow = 0x00000400; + static constexpr uint32_t __fpcr_trap_underflow = 0x00000800; + static constexpr uint32_t __fpcr_trap_inexact = 0x00001000; + static constexpr uint32_t __fpcr_flush_to_zero = 0x01000000; +#endif + // Zero-th bit is the first bit. static constexpr uint32_t ROUNDING_CONTROL_BIT_POSITION = 22; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
