[libcxx-commits] [libcxx] Remove incorrect forward-declaration of lgamma_r header (PR #80979)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 29 08:15:32 PST 2024
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/80979
>From ba53d6ba57898b343a125751c5fed12f53e76efd Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov <thegeorg at yandex-team.com>
Date: Wed, 7 Feb 2024 12:54:41 +0100
Subject: [PATCH 1/3] Remove incorrect forward-declaration of lgamma_r header
libc++ declares `lgamma_r` as:
```
extern "C" double lgamma_r(double, int *);
```
while modern glibc uses the following:
```
__MATHCALL (lgamma,_r, (_Mdouble_, int *__signgamp));
```
This causes (I did not digged to the very bottom of it) the following compilation error when compiling with nvcc:
```
libcxx/include/__random/binomial_distribution.h(117): error: linkage specification is incompatible with previous "lgamma_r"
/usr/include/x86_64-linux-gnu/bits/mathcalls.h(271): here
```
---
libcxx/include/__random/binomial_distribution.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index e8774bb8d67ee1..54f321af63d50b 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -97,10 +97,6 @@ class _LIBCPP_TEMPLATE_VIS binomial_distribution {
}
};
-#ifndef _LIBCPP_MSVCRT_LIKE
-extern "C" double lgamma_r(double, int*);
-#endif
-
inline _LIBCPP_HIDE_FROM_ABI double __libcpp_lgamma(double __d) {
#if defined(_LIBCPP_MSVCRT_LIKE)
return lgamma(__d);
>From e7be921fc60af42a1c3a7ae071f18cfe328843b6 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov <thegeorg at yandex-team.com>
Date: Wed, 7 Feb 2024 22:37:26 +0300
Subject: [PATCH 2/3] Define _REENTRANT prior to including math.h on macOS
---
libcxx/include/math.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 05989734c26c66..5a07448130fedc 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -297,6 +297,10 @@ long double truncl(long double x);
# pragma GCC system_header
# endif
+# if defined(__APPLE__)
+# define _REENTRANT
+# endif
+
# if __has_include_next(<math.h>)
# include_next <math.h>
# endif
>From 85b094c47d907d097f5e4c9aa3ca27040d1bc8d7 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 29 Feb 2024 11:15:24 -0500
Subject: [PATCH 3/3] Update libcxx/include/math.h
---
libcxx/include/math.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 5a07448130fedc..0e8bf8f1f65a23 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -297,7 +297,10 @@ long double truncl(long double x);
# pragma GCC system_header
# endif
-# if defined(__APPLE__)
+// This is required to define functions like lgamma_r on Apple platforms.
+// These functions are not required by the Standard but our implementation
+// uses them.
+# if defined(__APPLE__) && !defined(_REENTRANT)
# define _REENTRANT
# endif
More information about the libcxx-commits
mailing list