[libc-commits] [libc] [llvm] [libc][math] Refactor isnan family to header-only (PR #195598)
via libc-commits
libc-commits at lists.llvm.org
Mon May 4 00:31:09 PDT 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/195598
>From 52d790b77e1343f21fd3b3a9b1474f0b26d5e67d Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Mon, 4 May 2026 09:57:24 +0300
Subject: [PATCH 1/2] [libc][math] Refactor isnan family to header-only
Refactored functions:
- isnan
- isnanf
---
.../cmake/modules/CheckCompilerFeatures.cmake | 3 ++
.../modules/LLVMLibCCompileOptionRules.cmake | 3 ++
.../compiler_features/check_builtin_isnan.cpp | 5 ++
libc/shared/math.h | 3 ++
libc/shared/math/isnan.h | 23 +++++++++
libc/shared/math/isnanf.h | 23 +++++++++
libc/shared/math/isnanl.h | 23 +++++++++
libc/src/__support/math/CMakeLists.txt | 27 +++++++++++
libc/src/__support/math/isnan.h | 29 +++++++++++
libc/src/__support/math/isnanf.h | 29 +++++++++++
libc/src/__support/math/isnanl.h | 29 +++++++++++
libc/src/math/generic/CMakeLists.txt | 2 +-
libc/src/math/generic/isnan.cpp | 5 +-
libc/src/math/generic/isnanf.cpp | 5 +-
libc/src/math/generic/isnanl.cpp | 5 +-
libc/test/shared/CMakeLists.txt | 6 +++
.../shared/shared_math_constexpr_test.cpp | 3 ++
libc/test/shared/shared_math_test.cpp | 3 ++
.../llvm-project-overlay/libc/BUILD.bazel | 48 +++++++++++++++++++
19 files changed, 264 insertions(+), 10 deletions(-)
create mode 100644 libc/cmake/modules/compiler_features/check_builtin_isnan.cpp
create mode 100644 libc/shared/math/isnan.h
create mode 100644 libc/shared/math/isnanf.h
create mode 100644 libc/shared/math/isnanl.h
create mode 100644 libc/src/__support/math/isnan.h
create mode 100644 libc/src/__support/math/isnanf.h
create mode 100644 libc/src/__support/math/isnanl.h
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index 4d50d81e0ce45..85f6c6ca1c807 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -7,6 +7,7 @@ set(
"builtin_ceil_floor_rint_trunc"
"builtin_fmax_fmin"
"builtin_fmaxf16_fminf16"
+ "builtin_isnan"
"builtin_round"
"builtin_roundeven"
"float16"
@@ -123,6 +124,8 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
set(LIBC_COMPILER_HAS_BUILTIN_FMAX_FMIN TRUE)
elseif(${feature} STREQUAL "builtin_fmaxf16_fminf16")
set(LIBC_COMPILER_HAS_BUILTIN_FMAXF16_FMINF16 TRUE)
+ elseif(${feature} STREQUAL "builtin_isnan")
+ set(LIBC_COMPILER_HAS_BUILTIN_ISNAN TRUE)
elseif(${feature} STREQUAL "builtin_round")
set(LIBC_COMPILER_HAS_BUILTIN_ROUND TRUE)
elseif(${feature} STREQUAL "builtin_roundeven")
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index ea86659cd5590..2d3703eefa0ac 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -52,6 +52,9 @@ function(_get_compile_options_from_flags output_var)
list(APPEND compile_options "-mfma")
endif()
endif()
+ if(LIBC_COMPILER_HAS_BUILTIN_ISNAN)
+ list(APPEND compile_options "-D__LIBC_USE_BUILTIN_ISNAN")
+ endif()
if(ADD_ROUND_OPT_FLAG)
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
# ROUND_OPT_FLAG is only enabled if SSE4.2 is detected, not just SSE4.1,
diff --git a/libc/cmake/modules/compiler_features/check_builtin_isnan.cpp b/libc/cmake/modules/compiler_features/check_builtin_isnan.cpp
new file mode 100644
index 0000000000000..b761833f9ac3d
--- /dev/null
+++ b/libc/cmake/modules/compiler_features/check_builtin_isnan.cpp
@@ -0,0 +1,5 @@
+int try_builtin_isnan(double x) { return __builtin_isnan(x); }
+int try_builtin_isnanf(float x) { return __builtin_isnan(x); }
+int try_builtin_isnanl(long double x) { return __builtin_isnan(x); }
+
+extern "C" void _start() {}
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 746f5270d8c84..73005f99a2db4 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -287,6 +287,9 @@
#include "math/iscanonicalf128.h"
#include "math/iscanonicalf16.h"
#include "math/iscanonicall.h"
+#include "math/isnan.h"
+#include "math/isnanf.h"
+#include "math/isnanl.h"
#include "math/issignaling.h"
#include "math/issignalingbf16.h"
#include "math/issignalingf.h"
diff --git a/libc/shared/math/isnan.h b/libc/shared/math/isnan.h
new file mode 100644
index 0000000000000..6039f309d3255
--- /dev/null
+++ b/libc/shared/math/isnan.h
@@ -0,0 +1,23 @@
+//===-- Shared isnan function -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ISNAN_H
+#define LLVM_LIBC_SHARED_MATH_ISNAN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnan.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnan;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNAN_H
diff --git a/libc/shared/math/isnanf.h b/libc/shared/math/isnanf.h
new file mode 100644
index 0000000000000..2858342fb13c0
--- /dev/null
+++ b/libc/shared/math/isnanf.h
@@ -0,0 +1,23 @@
+//===-- Shared isnanf function ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ISNANF_H
+#define LLVM_LIBC_SHARED_MATH_ISNANF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnanf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnanf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNANF_H
diff --git a/libc/shared/math/isnanl.h b/libc/shared/math/isnanl.h
new file mode 100644
index 0000000000000..4cc3b90b5bcf7
--- /dev/null
+++ b/libc/shared/math/isnanl.h
@@ -0,0 +1,23 @@
+//===-- Shared isnanl function ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ISNANL_H
+#define LLVM_LIBC_SHARED_MATH_ISNANL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/isnanl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::isnanl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ISNANL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 32a85c291d628..9e3ec26cdc881 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1677,6 +1677,33 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ isnan
+ HDRS
+ isnan.h
+ DEPENDS
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ isnanf
+ HDRS
+ isnanf.h
+ DEPENDS
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ isnanl
+ HDRS
+ isnanl.h
+ DEPENDS
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.config
+)
+
add_header_library(
issignaling
HDRS
diff --git a/libc/src/__support/math/isnan.h b/libc/src/__support/math/isnan.h
new file mode 100644
index 0000000000000..c09294ba6967e
--- /dev/null
+++ b/libc/src/__support/math/isnan.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for isnan -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ISNAN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNAN_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE LIBC_CONSTEXPR int isnan(double x) {
+#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
+ return __builtin_isnan(x);
+#else
+ return fputil::FPBits<double>(x).is_nan();
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNAN_H
diff --git a/libc/src/__support/math/isnanf.h b/libc/src/__support/math/isnanf.h
new file mode 100644
index 0000000000000..1f3ee4f7a0803
--- /dev/null
+++ b/libc/src/__support/math/isnanf.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for isnanf ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ISNANF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANF_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE LIBC_CONSTEXPR int isnanf(float x) {
+#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
+ return __builtin_isnan(x);
+#else
+ return fputil::FPBits<float>(x).is_nan();
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNANF_H
diff --git a/libc/src/__support/math/isnanl.h b/libc/src/__support/math/isnanl.h
new file mode 100644
index 0000000000000..51e78ae4131a6
--- /dev/null
+++ b/libc/src/__support/math/isnanl.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for isnanl ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ISNANL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ISNANL_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE LIBC_CONSTEXPR int isnanl(long double x) {
+#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
+ return __builtin_isnan(x);
+#else
+ return fputil::FPBits<long double>(x).is_nan();
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ISNANL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 5ccd2b3af1c2b..fe0e2663e7628 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3042,7 +3042,7 @@ add_entrypoint_object(
HDRS
../nan.h
DEPENDS
- libc.src.__support.math.nan
+ libc.src.__support.math.isnanl
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/isnan.cpp b/libc/src/math/generic/isnan.cpp
index 73230a4e9a299..68392a709ca8d 100644
--- a/libc/src/math/generic/isnan.cpp
+++ b/libc/src/math/generic/isnan.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnan.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnan.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnan, (double x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnan, (double x)) { return math::isnan(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/isnanf.cpp b/libc/src/math/generic/isnanf.cpp
index a1d814eab1825..40cdb01297c2a 100644
--- a/libc/src/math/generic/isnanf.cpp
+++ b/libc/src/math/generic/isnanf.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnanf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnanf.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnanf, (float x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnanf, (float x)) { return math::isnanf(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/isnanl.cpp b/libc/src/math/generic/isnanl.cpp
index 57ce79f3c7b47..b9bd4518e9475 100644
--- a/libc/src/math/generic/isnanl.cpp
+++ b/libc/src/math/generic/isnanl.cpp
@@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/isnanl.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/isnanl.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, isnanl, (long double x)) { return __builtin_isnan(x); }
+LLVM_LIBC_FUNCTION(int, isnanl, (long double x)) { return math::isnanl(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 81e7a24a977e8..8ebc1a81fe45b 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -284,6 +284,9 @@ add_fp_unittest(
libc.src.__support.math.iscanonicalf128
libc.src.__support.math.iscanonicalf16
libc.src.__support.math.iscanonicall
+ libc.src.__support.math.isnan
+ libc.src.__support.math.isnanf
+ libc.src.__support.math.isnanl
libc.src.__support.math.issignaling
libc.src.__support.math.issignalingbf16
libc.src.__support.math.issignalingf
@@ -647,6 +650,9 @@ add_fp_unittest(
libc.src.__support.math.iscanonicalf128
libc.src.__support.math.iscanonicalf16
libc.src.__support.math.iscanonicall
+ libc.src.__support.math.isnan
+ libc.src.__support.math.isnanf
+ libc.src.__support.math.isnanl
libc.src.__support.math.issignaling
libc.src.__support.math.issignalingbf16
libc.src.__support.math.issignalingf
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 21bcdc422c8d8..ac26ce4f0bd69 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -88,6 +88,7 @@ static_assert(1 == [] {
static_assert(0.0 == LIBC_NAMESPACE::shared::round(0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::roundeven(0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::trunc(0.0));
+static_assert(0 == LIBC_NAMESPACE::shared::isnan(0.0));
//===----------------------------------------------------------------------===//
// Float Tests
@@ -162,6 +163,7 @@ static_assert(1 == [] {
static_assert(0.0f == LIBC_NAMESPACE::shared::roundf(0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::roundevenf(0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::truncf(0.0f));
+static_assert(0 == LIBC_NAMESPACE::shared::isnanf(0.0f));
//===----------------------------------------------------------------------===//
// Float16 Tests
@@ -341,6 +343,7 @@ static_assert(1 == [] {
static_assert(0.0L == LIBC_NAMESPACE::shared::roundl(0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::roundevenl(0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::truncl(0.0L));
+static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
#endif
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index a11f5d50c022b..6257ab64da666 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -313,6 +313,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::roundf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::roundevenf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::truncf(0.0f));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanf(0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -447,6 +448,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::round(0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::roundeven(0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::trunc(0.0));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnan(0.0));
}
// TODO: Enable the tests when double-double type is supported.
@@ -563,6 +565,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::roundl(0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::roundevenl(0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::truncl(0.0L));
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanl(0.0L));
}
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 6bb1c47c06d98..af601768b984a 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4877,6 +4877,33 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_isnan",
+ hdrs = ["src/__support/math/isnan.h"],
+ deps = [
+ ":__support_fputil_fp_bits",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_isnanf",
+ hdrs = ["src/__support/math/isnanf.h"],
+ deps = [
+ ":__support_fputil_fp_bits",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_isnanl",
+ hdrs = ["src/__support/math/isnanl.h"],
+ deps = [
+ ":__support_fputil_fp_bits",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_issignaling",
hdrs = ["src/__support/math/issignaling.h"],
@@ -9474,6 +9501,27 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "isnan",
+ additional_deps = [
+ ":__support_math_isnan",
+ ],
+)
+
+libc_math_function(
+ name = "isnanf",
+ additional_deps = [
+ ":__support_math_isnanf",
+ ],
+)
+
+libc_math_function(
+ name = "isnanl",
+ additional_deps = [
+ ":__support_math_isnanl",
+ ],
+)
+
libc_math_function(
name = "issignaling",
additional_deps = [
>From 6ac9163e9a0ce631e63c65752fcb0dc3bedb7d59 Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Mon, 4 May 2026 10:08:40 +0300
Subject: [PATCH 2/2] undef gcc builtens
---
libc/src/__support/math/isnan.h | 1 +
libc/src/__support/math/isnanf.h | 1 +
libc/src/__support/math/isnanl.h | 1 +
libc/src/math/generic/CMakeLists.txt | 8 +++++++-
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/math/isnan.h b/libc/src/__support/math/isnan.h
index c09294ba6967e..fb4a68c5f6a96 100644
--- a/libc/src/__support/math/isnan.h
+++ b/libc/src/__support/math/isnan.h
@@ -15,6 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
+#undef isnan
LIBC_INLINE LIBC_CONSTEXPR int isnan(double x) {
#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_isnan(x);
diff --git a/libc/src/__support/math/isnanf.h b/libc/src/__support/math/isnanf.h
index 1f3ee4f7a0803..a6315d1f93be9 100644
--- a/libc/src/__support/math/isnanf.h
+++ b/libc/src/__support/math/isnanf.h
@@ -15,6 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
+#undef isnanf
LIBC_INLINE LIBC_CONSTEXPR int isnanf(float x) {
#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_isnan(x);
diff --git a/libc/src/__support/math/isnanl.h b/libc/src/__support/math/isnanl.h
index 51e78ae4131a6..ac34beccc8510 100644
--- a/libc/src/__support/math/isnanl.h
+++ b/libc/src/__support/math/isnanl.h
@@ -15,6 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
+#undef isnanl
LIBC_INLINE LIBC_CONSTEXPR int isnanl(long double x) {
#if defined(__LIBC_USE_BUILTIN_ISNAN) && !defined(LIBC_HAS_CONSTANT_EVALUATION)
return __builtin_isnan(x);
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index fe0e2663e7628..7ccbddba07b8d 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3017,6 +3017,8 @@ add_entrypoint_object(
isnan.cpp
HDRS
../isnan.h
+ DEPENDS
+ libc.src.__support.math.isnan
)
add_entrypoint_object(
@@ -3025,6 +3027,8 @@ add_entrypoint_object(
isnanf.cpp
HDRS
../isnanf.h
+ DEPENDS
+ libc.src.__support.math.isnanf
)
add_entrypoint_object(
@@ -3033,6 +3037,8 @@ add_entrypoint_object(
isnanl.cpp
HDRS
../isnanl.h
+ DEPENDS
+ libc.src.__support.math.isnanl
)
add_entrypoint_object(
@@ -3042,7 +3048,7 @@ add_entrypoint_object(
HDRS
../nan.h
DEPENDS
- libc.src.__support.math.isnanl
+ libc.src.__support.math.nan
)
add_entrypoint_object(
More information about the libc-commits
mailing list