From 5d07eab6feba55e06d3380880b5a4e7570f796fd Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 8 Sep 2021 17:38:19 -0700 Subject: [PATCH] [shims] Only define atomic shims in Swift's Clang Importer Per #37, we currently happen to use some non-standard C atomics that only work in Clang; to prevent issues when this module gets compiled using other compilers, `#ifdef` out all the actual shims, leaving only the definitions for `retain_n`/`release_n`. (For example, CMake builds the shims module using the system C compiler by default, which is usually GCC on Linux.) --- Sources/_AtomicsShims/include/_AtomicsShims.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/_AtomicsShims/include/_AtomicsShims.h b/Sources/_AtomicsShims/include/_AtomicsShims.h index bcec8d6..c1614f1 100644 --- a/Sources/_AtomicsShims/include/_AtomicsShims.h +++ b/Sources/_AtomicsShims/include/_AtomicsShims.h @@ -56,8 +56,13 @@ #include #include -#include #include +// The atomic primitives are only needed when this is compiled using Swift's +// Clang Importer. This allows us to continue reling on some Clang extensions +// (see https://github.com/apple/swift-atomics/issues/37). +#if defined(__swift__) +# include +#endif // For now, assume double-wide atomics are available everywhere, // except on Linux/x86_64, where they need to be manually enabled @@ -73,6 +78,8 @@ # endif #endif +#if defined(__swift__) + #define SWIFTATOMIC_INLINE static inline __attribute__((__always_inline__)) #define SWIFTATOMIC_SWIFT_NAME(name) __attribute__((swift_name(#name))) @@ -348,6 +355,8 @@ SWIFTATOMIC_DEFINE_TYPE(COMPLEX, DoubleWord, _sa_dword, _sa_double_word_ctype) SWIFTATOMIC_STORAGE_TYPE(DoubleWord, _sa_dword, _sa_double_word_ctype) #endif +#endif // __swift__ + #if ENABLE_DOUBLEWIDE_ATOMICS extern void _sa_retain_n(void *object, uint32_t n); extern void _sa_release_n(void *object, uint32_t n);