-
Notifications
You must be signed in to change notification settings - Fork 11.5k
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
[libc] use LIBC_HAS_BUILTIN instead __has_builtin #82377
[libc] use LIBC_HAS_BUILTIN instead __has_builtin #82377
Conversation
@llvm/pr-subscribers-libc Author: Schrodinger ZHU Yifan (SchrodingerZhu) Changesfix the issue that Full diff: https://github.com/llvm/llvm-project/pull/82377.diff 1 Files Affected:
diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index c10d06c04bccad..b74cb5981dbaf8 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -166,7 +166,7 @@ LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) {
// except no instructions for memory ordering are issued. Only reordering of
// the instructions by the compiler is suppressed as order instructs.
LIBC_INLINE void atomic_signal_fence([[maybe_unused]] MemoryOrder mem_ord) {
-#if __has_builtin(__atomic_signal_fence)
+#if LIBC_HAS_BUILTIN(__atomic_signal_fence)
__atomic_signal_fence(static_cast<int>(mem_ord));
#else
// if the builtin is not ready, use asm as a full compiler barrier.
|
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.
The GPU has __has_builtin
, that's a clang
thing, see https://godbolt.org/z/1MPozEor1. However, we are supposed to be consistent with the LIBC_
prefixed stuff.
@@ -166,7 +166,7 @@ LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) { | |||
// except no instructions for memory ordering are issued. Only reordering of | |||
// the instructions by the compiler is suppressed as order instructs. | |||
LIBC_INLINE void atomic_signal_fence([[maybe_unused]] MemoryOrder mem_ord) { | |||
#if __has_builtin(__atomic_signal_fence) | |||
#if LIBC_HAS_BUILTIN(__atomic_signal_fence) |
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.
constexpr if
would be a good fit here as well.
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.
it seems that clang would not be happy with unknown function in constexpr if
: https://godbolt.org/z/xeGevdqzW
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.
Ah, yeah. I remember running into that because constexpr
is only evaluated after the AST is built.
fix the issue that
__has_builtin
is undefined on some non-clang targets.