]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/tsan/Darwin/gcd-sync-block-copy.mm
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / tsan / Darwin / gcd-sync-block-copy.mm
1 // This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
2
3 // RUN: %clang_tsan -fno-sanitize=thread %s -o %t_no_tsan -framework Foundation
4 // RUN: %run %t_no_tsan 2>&1 | FileCheck %s
5
6 // RUN: %clang_tsan %s -o %t_with_tsan -framework Foundation
7 // RUN: %run %t_with_tsan 2>&1 | FileCheck %s
8
9 #import <Foundation/Foundation.h>
10
11 @interface MyClass : NSObject
12 @end
13
14 @implementation MyClass
15 - (instancetype)retain {
16   // Copying the dispatch_sync'd block below will increment the retain count of
17   // this object. Abort if that happens.
18   abort();
19 }
20 @end
21
22 int main(int argc, const char* argv[]) {
23   dispatch_queue_t q = dispatch_queue_create("my.queue", NULL);
24   id object = [[MyClass alloc] init];
25   dispatch_sync(q, ^{
26     NSLog(@"%@", object);
27   });
28   [object release];
29   NSLog(@"Done.");
30   return 0;
31 }
32
33 // CHECK: Done.
34 // CHECK-NOT: WARNING: ThreadSanitizer