Skip to content

Commit

Permalink
[builtins][libc++] Allow building atomics after latest merge
Browse files Browse the repository at this point in the history
These projects now check for __atomic_always_lock_free on uintptr_t which
returns false for purecap until the pull request
#721 is merged.
  • Loading branch information
arichardson committed Dec 12, 2023
1 parent 78a35eb commit 881f119
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler-rt/lib/builtins/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ __inline static void lock(Lock *l) { OSSpinLockLock(l); }
static Lock locks[SPINLOCK_COUNT]; // initialized to OS_SPINLOCK_INIT which is 0

#else
#ifndef __CHERI_PURE_CAPABILITY__
// FIXME: needs https://github.com/CTSRD-CHERI/llvm-project/pull/721
_Static_assert(__atomic_always_lock_free(sizeof(uintptr_t), 0),
"Implementation assumes lock-free pointer-size cmpxchg");
#endif
typedef _Atomic(uintptr_t) Lock;
/// Unlock a lock. This is a release operation.
__inline static void unlock(Lock *l) {
Expand Down
7 changes: 7 additions & 0 deletions libcxx/include/atomic
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,13 @@ _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,

template<typename _Tp> struct __cxx_is_always_lock_free {
enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; };
#ifdef __CHERI_PURE_CAPABILITY__
// FIXME: can be removed after https://github.com/CTSRD-CHERI/llvm-project/pull/721 lands
template<typename _Tp> struct __cxx_is_always_lock_free<intptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
template<typename _Tp> struct __cxx_is_always_lock_free<uintptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
#endif

#else

Expand Down

0 comments on commit 881f119

Please sign in to comment.