[ubsan] Use __sanitizer::atomic_exchange(), prefer shared impl.
authorWill Dietz <wdietz2@illinois.edu>
Mon, 14 Jan 2013 16:13:52 +0000 (16:13 +0000)
committerWill Dietz <wdietz2@illinois.edu>
Mon, 14 Jan 2013 16:13:52 +0000 (16:13 +0000)
Specify weaker memory order in case we optimize for it in the future,
presently still doing same __sync_lock_test_and_set() as before.

Change suggested by Alexey Samsonov, thanks!

llvm-svn: 172429

compiler-rt/lib/ubsan/ubsan_value.h

index 267388b..e673f7a 100644 (file)
@@ -20,6 +20,7 @@
 #error "UBSan not supported for this platform!"
 #endif
 
+#include "sanitizer_common/sanitizer_atomic.h"
 #include "sanitizer_common/sanitizer_common.h"
 
 // FIXME: Move this out to a config header.
@@ -64,7 +65,9 @@ public:
   /// \brief Atomically acquire a copy, disabling original in-place.
   /// Exactly one call to acquire() returns a copy that isn't disabled.
   SourceLocation acquire() {
-    u32 OldColumn = __sync_lock_test_and_set(&Column, ~u32(0));
+    u32 OldColumn = __sanitizer::atomic_exchange(
+                        (__sanitizer::atomic_uint32_t *)&Column, ~u32(0),
+                        __sanitizer::memory_order_relaxed);
     return SourceLocation(Filename, Line, OldColumn);
   }