[PATCH] D21609: [tsan] Intercept libcxx __release_shared to avoid false positive with weak_ptrs and destructors in C++

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 11:21:38 PDT 2016


dvyukov added inline comments.

================
Comment at: lib/tsan/rtl/tsan_interceptors_mac.cc:286
@@ +285,3 @@
+// atomic decrement that is used to check when the object's refcount drops to 0.
+STDCXX_INTERCEPTOR(void, _ZNSt3__119__shared_weak_count16__release_sharedEv,
+                   void *o) {
----------------
Why we don't need to intercept release of weak references?
Is it that last shared references releases weak, or vice versa?

================
Comment at: lib/tsan/rtl/tsan_interceptors_mac.cc:289
@@ +288,3 @@
+  SCOPED_INTERCEPTOR_RAW(_ZNSt3__119__shared_weak_count16__release_sharedEv, o);
+  Acquire(thr, pc, (uptr)o);
+  Release(thr, pc, (uptr)o);
----------------
I think Acquire should happen _after_ the actual release to synchronize with all preceding Release's.
Normally,  you can't touch the object after release in all but the last thread, because the object can already be freed (unmapped). So ideally we need to determine the last thread and do Acquire only in it.
But I wonder if tsan Release is OK -- it won't touch object memory.



http://reviews.llvm.org/D21609





More information about the llvm-commits mailing list