diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp @@ -12,6 +12,18 @@ #include "sanitizer_common/sanitizer_atomic.h" #include "gtest/gtest.h" +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +#if __has_extension(c_atomic) || __has_extension(cxx_atomic) +#define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE +#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) +#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE +#else +#error Unsupported compiler. +#endif + namespace __sanitizer { template @@ -69,11 +81,15 @@ CheckStoreLoad(); CheckStoreLoad(); + // Avoid fallbacking to software emulated compiler atomics, that are usually + // provided by libatomic, which is not always present. +#if ATOMIC_LLONG_LOCK_FREE == 2 CheckStoreLoad(); CheckStoreLoad(); CheckStoreLoad(); CheckStoreLoad(); CheckStoreLoad(); +#endif CheckStoreLoad (); @@ -119,7 +135,9 @@ CheckAtomicCompareExchange(); CheckAtomicCompareExchange(); CheckAtomicCompareExchange(); +#if ATOMIC_LLONG_LOCK_FREE == 2 CheckAtomicCompareExchange(); +#endif CheckAtomicCompareExchange(); } #endif //!SANITIZER_ANDROID