From: Kamil Rytarowski Date: Thu, 17 Sep 2020 14:02:59 +0000 (+0200) Subject: [compiler-rt] Avoid pulling libatomic to sanitizer tests X-Git-Tag: llvmorg-13-init~11741 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69516ddd028e8314f575a90bfca1724818fb5ca6;p=platform%2Fupstream%2Fllvm.git [compiler-rt] Avoid pulling libatomic to sanitizer tests Avoid fallbacking to software emulated compiler atomics, that are usually provided by libatomic, which is not always present. This fixes the test on NetBSD, which does not provide libatomic in base. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D87568 --- diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp index 9a3078b..3136886 100644 --- 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 @@ TEST(SanitizerCommon, AtomicStoreLoad) { 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 @@ TEST(SanitizerCommon, AtomicCompareExchangeTest) { CheckAtomicCompareExchange(); CheckAtomicCompareExchange(); CheckAtomicCompareExchange(); +#if ATOMIC_LLONG_LOCK_FREE == 2 CheckAtomicCompareExchange(); +#endif CheckAtomicCompareExchange(); } #endif //!SANITIZER_ANDROID