[PATCH] D21889: [tsan] Add support for GCD IO channels on Darwin

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 09:29:26 PDT 2016

dvyukov added inline comments.

Comment at: lib/tsan/rtl/tsan_libdispatch_mac.cc:512
@@ +511,3 @@
+  SCOPED_TSAN_INTERCEPTOR(dispatch_read, fd, length, q, h);
+  __block tsan_block_context_t new_context = {
+      q, nullptr, &invoke_block, false, false, false, 0};
Here is something I am missing.
Is new_context captured by reference or by value? Internet says that __block makes it captured by reference. But then doesn't new_h refer to a dangling stack location? new_context is stack allocated in this function, but new_h will be executed some time later.
And if it is captured by value, then synchronizing on address &new_context is pointless -- closure will have a different address.
What am I missing?

Comment at: lib/tsan/rtl/tsan_libdispatch_mac.cc:652
@@ +651,3 @@
+  SCOPED_TSAN_INTERCEPTOR(dispatch_io_create_with_io, type, io, q, h);
+  __block dispatch_io_t new_channel = nullptr;
+  __block tsan_block_context_t new_context = {
Also here: is it captured by value or by reference?
Or such variables somehow magically promoted to heap?


More information about the llvm-commits mailing list