[libc-commits] [libc] [llvm] [libc][math][c23] Switch `static_cast` to `fputil::cast` in `cbrtf16` (PR #204189)

Jordan Rupprecht via libc-commits libc-commits at lists.llvm.org
Tue Jun 16 09:15:03 PDT 2026


https://github.com/rupprecht created https://github.com/llvm/llvm-project/pull/204189

This avoids some failures w/ the compilers runtime

>From 74abdc5495c84682d73613f456802b03b6c5ab69 Mon Sep 17 00:00:00 2001
From: Jordan Rupprecht <rupprecht at google.com>
Date: Tue, 16 Jun 2026 09:12:20 -0700
Subject: [PATCH] Use fputil cast

---
 libc/src/__support/math/CMakeLists.txt            | 1 +
 libc/src/__support/math/cbrtf16.h                 | 3 ++-
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 25be4bd97bfda..bb60db5b8bdd1 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -765,6 +765,7 @@ add_header_library(
   HDRS
     cbrtf16.h
   DEPENDS
+    libc.src.__support.FPUtil.cast
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.multiply_add
diff --git a/libc/src/__support/math/cbrtf16.h b/libc/src/__support/math/cbrtf16.h
index a0348dafa2c6e..86fe985e75a74 100644
--- a/libc/src/__support/math/cbrtf16.h
+++ b/libc/src/__support/math/cbrtf16.h
@@ -15,6 +15,7 @@
 
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/cast.h"
 #include "src/__support/FPUtil/multiply_add.h"
 #include "src/__support/FPUtil/rounding_mode.h"
 #include "src/__support/macros/config.h"
@@ -174,7 +175,7 @@ LIBC_INLINE constexpr float16 cbrtf16(float16 x) {
 
   uint32_t r_bits = r_m | (static_cast<uint32_t>(out_e | sign_bit)
                            << FloatBits::FRACTION_LEN);
-  return static_cast<float16>(FloatBits(r_bits).get_val());
+  return fputil::cast<float16>(FloatBits(r_bits).get_val());
 }
 
 } // namespace math
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 8aa612f2b6179..0e20de90fd836 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4646,6 +4646,7 @@ libc_support_library(
     name = "__support_math_cbrtf16",
     hdrs = ["src/__support/math/cbrtf16.h"],
     deps = [
+        ":__support_fputil_cast",
         ":__support_fputil_fenv_impl",
         ":__support_fputil_fp_bits",
         ":__support_fputil_multiply_add",



More information about the libc-commits mailing list