[compiler-rt] 69516dd - [compiler-rt] Avoid pulling libatomic to sanitizer tests

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 07:04:20 PDT 2020


Author: Kamil Rytarowski
Date: 2020-09-17T16:04:06+02:00
New Revision: 69516ddd028e8314f575a90bfca1724818fb5ca6

URL: https://github.com/llvm/llvm-project/commit/69516ddd028e8314f575a90bfca1724818fb5ca6
DIFF: https://github.com/llvm/llvm-project/commit/69516ddd028e8314f575a90bfca1724818fb5ca6.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp

Removed: 
    


################################################################################
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 9a3078b25d76..3136886854fa 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<typename T>
@@ -69,11 +81,15 @@ TEST(SanitizerCommon, AtomicStoreLoad) {
   CheckStoreLoad<atomic_uint32_t, memory_order_relaxed, memory_order_release>();
   CheckStoreLoad<atomic_uint32_t, memory_order_seq_cst, memory_order_seq_cst>();
 
+  // 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<atomic_uint64_t, memory_order_relaxed, memory_order_relaxed>();
   CheckStoreLoad<atomic_uint64_t, memory_order_consume, memory_order_relaxed>();
   CheckStoreLoad<atomic_uint64_t, memory_order_acquire, memory_order_relaxed>();
   CheckStoreLoad<atomic_uint64_t, memory_order_relaxed, memory_order_release>();
   CheckStoreLoad<atomic_uint64_t, memory_order_seq_cst, memory_order_seq_cst>();
+#endif
 
   CheckStoreLoad<atomic_uintptr_t, memory_order_relaxed, memory_order_relaxed>
       ();
@@ -119,7 +135,9 @@ TEST(SanitizerCommon, AtomicCompareExchangeTest) {
   CheckAtomicCompareExchange<atomic_uint8_t>();
   CheckAtomicCompareExchange<atomic_uint16_t>();
   CheckAtomicCompareExchange<atomic_uint32_t>();
+#if ATOMIC_LLONG_LOCK_FREE == 2
   CheckAtomicCompareExchange<atomic_uint64_t>();
+#endif
   CheckAtomicCompareExchange<atomic_uintptr_t>();
 }
 #endif  //!SANITIZER_ANDROID


        


More information about the llvm-commits mailing list