[PATCH] D50920: [tsan] Avoid calling Block_copy in the "sync" GCD interceptors

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 14:25:20 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340342: [tsan] Avoid calling Block_copy in the "sync" GCD interceptors (authored by kuba.brecka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50920?vs=161315&id=161822#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50920

Files:
  compiler-rt/trunk/lib/tsan/rtl/tsan_libdispatch_mac.cc
  compiler-rt/trunk/test/tsan/Darwin/gcd-sync-block-copy.mm


Index: compiler-rt/trunk/test/tsan/Darwin/gcd-sync-block-copy.mm
===================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-sync-block-copy.mm
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-sync-block-copy.mm
@@ -0,0 +1,34 @@
+// This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
+
+// RUN: %clang_tsan -fno-sanitize=thread %s -o %t_no_tsan -framework Foundation
+// RUN: %run %t_no_tsan 2>&1 | FileCheck %s
+
+// RUN: %clang_tsan %s -o %t_with_tsan -framework Foundation
+// RUN: %run %t_with_tsan 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+ at interface MyClass : NSObject
+ at end
+
+ at implementation MyClass
+- (instancetype)retain {
+  // Copying the dispatch_sync'd block below will increment the retain count of
+  // this object. Abort if that happens.
+  abort();
+}
+ at end
+
+int main(int argc, const char* argv[]) {
+  dispatch_queue_t q = dispatch_queue_create("my.queue", NULL);
+  id object = [[MyClass alloc] init];
+  dispatch_sync(q, ^{
+    NSLog(@"%@", object);
+  });
+  [object release];
+  NSLog(@"Done.");
+  return 0;
+}
+
+// CHECK: Done.
+// CHECK-NOT: WARNING: ThreadSanitizer
Index: compiler-rt/trunk/lib/tsan/rtl/tsan_libdispatch_mac.cc
===================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_libdispatch_mac.cc
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_libdispatch_mac.cc
@@ -185,11 +185,8 @@
   TSAN_INTERCEPTOR(void, name, dispatch_queue_t q,                           \
                    DISPATCH_NOESCAPE dispatch_block_t block) {               \
     SCOPED_TSAN_INTERCEPTOR(name, q, block);                                 \
-    SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START();                           \
-    dispatch_block_t heap_block = Block_copy(block);                         \
-    SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_END();                             \
     tsan_block_context_t new_context = {                                     \
-        q, heap_block, &invoke_and_release_block, false, true, barrier, 0};  \
+        q, block, &invoke_and_release_block, false, true, barrier, 0};       \
     Release(thr, pc, (uptr)&new_context);                                    \
     SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START();                           \
     REAL(name##_f)(q, &new_context, dispatch_callback_wrap);                 \


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50920.161822.patch
Type: text/x-patch
Size: 2451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180821/72641b8a/attachment.bin>


More information about the llvm-commits mailing list