summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-04-07 11:33:44 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-04-07 11:33:44 +0000
commitfc2a80ee264e8390829178791d57c06a1ec875b6 (patch)
tree1e2e6578d81ab10a3c719d7515adad5944fdff2e /test
parenta8907b065bbc90768bdd07841377f89eb09d230f (diff)
[tsan] Fix synchronization in dispatch_sync
In the interceptor for dispatch_sync, we're currently missing synchronization between the callback and the code *after* the call to dispatch_sync. This patch fixes this by adding an extra release+acquire pair to dispatch_sync() and similar APIs. Added a testcase. Differential Revision: http://reviews.llvm.org/D18502 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@265659 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/tsan/Darwin/gcd-blocks.mm34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/tsan/Darwin/gcd-blocks.mm b/test/tsan/Darwin/gcd-blocks.mm
new file mode 100644
index 000000000..0dbff2758
--- /dev/null
+++ b/test/tsan/Darwin/gcd-blocks.mm
@@ -0,0 +1,34 @@
+// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+int main() {
+ fprintf(stderr, "start\n");
+
+ dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+ dispatch_queue_t main_q = dispatch_get_main_queue();
+
+ dispatch_async(background_q, ^{
+ __block long block_var = 0;
+
+ dispatch_sync(main_q, ^{
+ block_var = 42;
+ });
+
+ fprintf(stderr, "block_var = %ld\n", block_var);
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ CFRunLoopStop(CFRunLoopGetCurrent());
+ });
+ });
+
+ CFRunLoopRun();
+ fprintf(stderr, "done\n");
+}
+
+// CHECK: start
+// CHECK: block_var = 42
+// CHECK: done
+// CHECK-NOT: WARNING: ThreadSanitizer
+// CHECK-NOT: CHECK failed