[llvm-commits] [compiler-rt] r172429 - /compiler-rt/trunk/lib/ubsan/ubsan_value.h

Will Dietz wdietz2 at illinois.edu
Mon Jan 14 08:13:52 PST 2013


Author: wdietz2
Date: Mon Jan 14 10:13:52 2013
New Revision: 172429

URL: http://llvm.org/viewvc/llvm-project?rev=172429&view=rev
Log:
[ubsan] Use __sanitizer::atomic_exchange(), prefer shared impl.

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!

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_value.h

Modified: compiler-rt/trunk/lib/ubsan/ubsan_value.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_value.h?rev=172429&r1=172428&r2=172429&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_value.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_value.h Mon Jan 14 10:13:52 2013
@@ -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 @@
   /// \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);
   }
 





More information about the llvm-commits mailing list