[llvm-branch-commits] [libc] [libc][math] Fix aarch64 Darwin fenv implementation for full builds (PR #205016)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jun 21 16:46:28 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: jofrn

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/205016.diff


1 Files Affected:

- (modified) libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h (+27) 


``````````diff
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;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/205016


More information about the llvm-branch-commits mailing list