-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc++] Conditionally declare lgamma_r
as noexcept
#156547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[libc++] Conditionally declare lgamma_r
as noexcept
#156547
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
6844b07
to
ae1da16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think #153631 (comment) is rather what we should go for.
@llvm/pr-subscribers-libcxx Author: Yuxuan Chen (yuxuanchen1997) ChangesAn older PR #102036 suggested that LLVM libc declares This line usually don't cause issues because both the glibc and this file are included as "system headers". According to this godbolt, both GCC and clang ignore the different exception specification between multiple declarations if they are in system headers. However, this seems not the case for NVCC/EDG, so a fix for this redeclaration is still desirable. This patch proposes that we should declare the function as noexcept under known libc integrations to keep the declared function consistent. Full diff: https://github.com/llvm/llvm-project/pull/156547.diff 1 Files Affected:
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index b4b4340827761..80a910b611adf 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -97,13 +97,19 @@ class binomial_distribution {
}
};
-// 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*);
+// Some libc declares the math functions to be `noexcept`.
+#if _LIBCPP_GLIBC_PREREQ(2, 8) || defined(__LLVM_LIBC__)
+# define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT
+#else
+# define _LIBCPP_LGAMMA_R_NOEXCEPT
+#endif
+
+#if !defined(_LIBCPP_MSVCRT_LIKE)
+ extern "C" double lgamma_r(double, int*) _LIBCPP_LGAMMA_R_NOEXCEPT;
#endif
inline _LIBCPP_HIDE_FROM_ABI double __libcpp_lgamma(double __d) {
-#if defined(_LIBCPP_MSVCRT_LIKE) || defined(__LLVM_LIBC__)
+#if defined(_LIBCPP_MSVCRT_LIKE)
return lgamma(__d);
#else
int __sign;
|
Hi. Would appreciate progress on that work. If no one is working on it, I can also contribute some cycles. In the meantime, this patch can unblock some libc++ CUDA usages. |
c8a7ec2
to
b8be27e
Compare
b8be27e
to
a549e73
Compare
An older PR #102036 suggested that LLVM libc declares
lgamma_r
as noexcept and is incompatible with this redeclaration. However, I recently discovered that glibc also declares the math functions to be noexcept under C++ mode.This line usually don't cause issues because both the glibc and this file are included as "system headers". According to this godbolt, both GCC and clang ignore the different exception specification between multiple declarations if they are in system headers.
However, this seems not the case for NVCC/EDG, so a fix for this redeclaration is still desirable. This patch proposes that we should declare the function as noexcept under known libc integrations to keep the declared function consistent.