-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libcxx] Do not redeclare lgamma_r
when targeting the LLVM C library
#102036
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
Conversation
@llvm/pr-subscribers-libcxx Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/102036.diff 2 Files Affected:
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index 27f68d04e8a8d..a53ec7d5f7b4a 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 e8774bb8d67ee..3f19746bae238 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
|
@@ -38,7 +38,9 @@ | |||
# else | |||
# define _LIBCPP_GLIBC_PREREQ(a, b) 0 | |||
# endif // defined(__GLIBC_PREREQ) | |||
#endif // defined(__linux__) | |||
#elif defined(__AMDGPU__) || defined(__NVPTX__) |
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.
This makes me wonder if we should instead do this:
// <features.h> defines macros that allows detecting the libc we're using
#if __has_include(<features.h>)
# include <features.h>
#endif
#if defined(__GLIBC_PREREQ)
// etc...
#endif
Can you try that out and see if that breaks anything in the CI?
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.
ping |
1 similar comment
ping |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/2687 Here is the relevant piece of the build log for the reference
|
// To detect which libc we're using | ||
#if __has_include(<features.h>) |
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.
When pre-qualifying LLVM 20, we just found out that this breaks some code. Indeed, folks are free to have a header named <features.h>
available on their include paths, and in fact it seems not uncommon to have that. So the __has_include(<features.h>)
is going to lie, and the #include <features.h>
is going to pick up the wrong one anyway.
We'd need to find another header we can include to provide this version macro. Since C lacks a standardized header to provide version stuff (what a shame), we often rely on using some minimal header like <iso646.h>
to get implementation-specific values. That should work for glibc, and llvm-libc could be changed to provide a <iso646.h>
header. Also, all of llvm-libc's headers should define the feature macros like __LLVM_LIBC__
, which I think is not the case right now.
…library (llvm#102036)" This reverts commit 5f2389d. That commit started checking whether <features.h> was a valid include, however codebases are free to have such a header on their search path, which breaks compilation. LLVM libc should instead provide a more standard way of getting configuration macros like __LLVM_LIBC__.
Summary:
We use
lgamma_r
for the random normal distribution support. In thiscode we redeclare it, which caused issues with the LLVM C library as
this function is marked
noexcept
in LLVM libc. Also make sure we includefeatures.h
when using the GPU so it gets this as well.