diff --git a/compiler-rt/lib/scudo/standalone/atomic_helpers.h b/compiler-rt/lib/scudo/standalone/atomic_helpers.h --- a/compiler-rt/lib/scudo/standalone/atomic_helpers.h +++ b/compiler-rt/lib/scudo/standalone/atomic_helpers.h @@ -120,6 +120,14 @@ __ATOMIC_RELAXED); } +template +inline bool atomic_compare_exchange_weak(volatile T *A, typename T::Type *Cmp, + typename T::Type Xchg, + memory_order MO) { + return __atomic_compare_exchange(&A->ValDoNotUse, Cmp, &Xchg, true, MO, + __ATOMIC_RELAXED); +} + // Clutter-reducing helpers. template diff --git a/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp b/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/atomic_test.cpp @@ -88,6 +88,16 @@ EXPECT_FALSE(atomic_compare_exchange_strong( reinterpret_cast(&V), &OldVal, NewVal, memory_order_relaxed)); EXPECT_EQ(NewVal, OldVal); + + OldVal = 42; + NewVal = 24; + V = OldVal; + + EXPECT_TRUE(atomic_compare_exchange_weak(reinterpret_cast(&V), &OldVal, + NewVal, memory_order_relaxed)); + EXPECT_FALSE(atomic_compare_exchange_weak(reinterpret_cast(&V), &OldVal, + NewVal, memory_order_relaxed)); + EXPECT_EQ(NewVal, OldVal); } TEST(ScudoAtomicTest, AtomicCompareExchangeTest) {