[libcxx-commits] [libcxx] [libcxx] Do not redeclare `lgamma_r` when targeting the LLVM C library (PR #102036)
Joseph Huber via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 15 06:55:02 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/102036
>From abbae3ac9a1b3344cb07caf738d088cd917cedd1 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 5 Aug 2024 13:40:47 -0500
Subject: [PATCH 1/2] [libcxx] Do not redeclare `lgamma_r` when targeting the
LLVM C library
Summary:
We use `lgamma_r` for the random normal distrubtion support. In this
code we redeclare it, which caused issues with the LLVM C library as
this function has the `noexcept` flag. Also make sure we include
`features.h` when using the GPU so it gets this as well.
---
libcxx/include/__configuration/platform.h | 4 +++-
libcxx/include/__random/binomial_distribution.h | 3 ++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index 27f68d04e8a8d9..a53ec7d5f7b4ae 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -38,7 +38,9 @@
# else
# define _LIBCPP_GLIBC_PREREQ(a, b) 0
# endif // defined(__GLIBC_PREREQ)
-#endif // defined(__linux__)
+#elif defined(__AMDGPU__) || defined(__NVPTX__)
+# include <features.h>
+#endif
#ifndef __BYTE_ORDER__
# error \
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index e8774bb8d67ee1..3f19746bae238c 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -97,7 +97,8 @@ class _LIBCPP_TEMPLATE_VIS binomial_distribution {
}
};
-#ifndef _LIBCPP_MSVCRT_LIKE
+// The LLVM C library provides this with conflicting `noexcept` attributes.
+#if !defined(_LIBCPP_MSVCRT_LIKE) && !defined(__LLVM_LIBC__)
extern "C" double lgamma_r(double, int*);
#endif
>From 219c9232212d9acf2c3105aba92ec0c8b0928227 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 14 Aug 2024 12:16:12 -0500
Subject: [PATCH 2/2] Address comments
---
libcxx/include/__configuration/platform.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index a53ec7d5f7b4ae..2a92ce209b91f8 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -30,16 +30,17 @@
// ... add new file formats here ...
#endif
-// Need to detect which libc we're using if we're on Linux.
-#if defined(__linux__)
+// To detect which libc we're using
+#if __has_include(<features.h>)
# include <features.h>
+#endif
+
+#if defined(__linux__)
# if defined(__GLIBC_PREREQ)
# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
# else
# define _LIBCPP_GLIBC_PREREQ(a, b) 0
# endif // defined(__GLIBC_PREREQ)
-#elif defined(__AMDGPU__) || defined(__NVPTX__)
-# include <features.h>
#endif
#ifndef __BYTE_ORDER__
More information about the libcxx-commits
mailing list