Skip to content

Commit c0a0c11

Browse files
committed
[builtins][libc++] Allow building atomics after latest merge
These projects now check for __atomic_always_lock_free on uintptr_t which returns false for purecap until the pull request #721 is merged.
1 parent 78a35eb commit c0a0c11

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compiler-rt/lib/builtins/atomic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ __inline static void lock(Lock *l) { OSSpinLockLock(l); }
9292
static Lock locks[SPINLOCK_COUNT]; // initialized to OS_SPINLOCK_INIT which is 0
9393

9494
#else
95+
#ifndef __CHERI_PURE_CAPABILITY__
96+
// FIXME: needs https://github.com/CTSRD-CHERI/llvm-project/pull/721
9597
_Static_assert(__atomic_always_lock_free(sizeof(uintptr_t), 0),
9698
"Implementation assumes lock-free pointer-size cmpxchg");
99+
#endif
97100
typedef _Atomic(uintptr_t) Lock;
98101
/// Unlock a lock. This is a release operation.
99102
__inline static void unlock(Lock *l) {

libcxx/include/atomic

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,13 @@ _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
14081408

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

14121419
#else
14131420

0 commit comments

Comments
 (0)