[libcxx-commits] [libcxx] Remove incorrect forward-declaration of lgamma_r header (PR #80979)

Yuriy Chernyshov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 7 11:37:46 PST 2024


https://github.com/georgthegreat 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/2] 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 af4e77127d5c46edfa953ed9a76949b867535c31 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/2] 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..89cb942f25eb93 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



More information about the libcxx-commits mailing list