aboutsummaryrefslogtreecommitdiff
path: root/test/tsan/Darwin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:48 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:48 +0000
commit93c1b73a09a52d4a265f683bf1954b08bb430049 (patch)
tree5543464d74945196cc890e9d9099e5d0660df7eb /test/tsan/Darwin
parent0d8e7490d6e8a13a8f0977d9b7771803b9f64ea0 (diff)
downloadsrc-93c1b73a09a52d4a265f683bf1954b08bb430049.tar.gz
src-93c1b73a09a52d4a265f683bf1954b08bb430049.zip
Vendor import of compiler-rt trunk r338150:vendor/compiler-rt/compiler-rt-trunk-r338150
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=336817 svn path=/vendor/compiler-rt/compiler-rt-trunk-r338150/; revision=336818; tag=vendor/compiler-rt/compiler-rt-trunk-r338150
Diffstat (limited to 'test/tsan/Darwin')
-rw-r--r--test/tsan/Darwin/external-swift-debugging.cc68
-rw-r--r--test/tsan/Darwin/gcd-after-null.mm23
-rw-r--r--test/tsan/Darwin/norace-objcxx-run-time.mm2
-rw-r--r--test/tsan/Darwin/objc-synchronize-tagged.mm62
-rw-r--r--test/tsan/Darwin/objc-synchronize.mm57
5 files changed, 188 insertions, 24 deletions
diff --git a/test/tsan/Darwin/external-swift-debugging.cc b/test/tsan/Darwin/external-swift-debugging.cc
new file mode 100644
index 000000000000..603734e5d035
--- /dev/null
+++ b/test/tsan/Darwin/external-swift-debugging.cc
@@ -0,0 +1,68 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %deflake %run %t 2>&1 | FileCheck %s
+
+#include <thread>
+
+#import "../test.h"
+
+
+extern "C" {
+int __tsan_get_report_data(void *report, const char **description, int *count,
+ int *stack_count, int *mop_count, int *loc_count,
+ int *mutex_count, int *thread_count,
+ int *unique_tid_count, void **sleep_trace,
+ unsigned long trace_size);
+int __tsan_get_report_tag(void *report, unsigned long *tag);
+}
+
+__attribute__((no_sanitize("thread"), noinline))
+void ExternalWrite(void *addr) {
+ void *kSwiftAccessRaceTag = (void *)0x1;
+ __tsan_external_write(addr, nullptr, kSwiftAccessRaceTag);
+}
+
+int main(int argc, char *argv[]) {
+ barrier_init(&barrier, 2);
+ fprintf(stderr, "Start.\n");
+ // CHECK: Start.
+
+ void *opaque_object = malloc(16);
+ std::thread t1([opaque_object] {
+ ExternalWrite(opaque_object);
+ barrier_wait(&barrier);
+ });
+ std::thread t2([opaque_object] {
+ barrier_wait(&barrier);
+ ExternalWrite(opaque_object);
+ });
+ // CHECK: WARNING: ThreadSanitizer: Swift access race
+ // CHECK: Modifying access of Swift variable at {{.*}} by thread {{.*}}
+ // CHECK: Previous modifying access of Swift variable at {{.*}} by thread {{.*}}
+ // CHECK: SUMMARY: ThreadSanitizer: Swift access race
+ t1.join();
+ t2.join();
+
+ fprintf(stderr, "Done.\n");
+}
+
+extern "C"
+void __tsan_on_report(void *report) {
+ const char *description;
+ int count;
+ int stack_count, mop_count, loc_count, mutex_count, thread_count,
+ unique_tid_count;
+ void *sleep_trace[16] = {0};
+ __tsan_get_report_data(report, &description, &count, &stack_count, &mop_count,
+ &loc_count, &mutex_count, &thread_count,
+ &unique_tid_count, sleep_trace, 16);
+ fprintf(stderr, "report type = '%s', count = %d\n", description, count);
+ // CHECK: report type = 'external-race', count = 0
+
+ unsigned long tag;
+ __tsan_get_report_tag(report, &tag);
+ fprintf(stderr, "tag = %ld\n", tag);
+ // CHECK: tag = 1
+}
+
+// CHECK: Done.
+// CHECK: ThreadSanitizer: reported 1 warnings
diff --git a/test/tsan/Darwin/gcd-after-null.mm b/test/tsan/Darwin/gcd-after-null.mm
deleted file mode 100644
index 7c9913c0fb17..000000000000
--- a/test/tsan/Darwin/gcd-after-null.mm
+++ /dev/null
@@ -1,23 +0,0 @@
-// Regression test to make sure we don't crash when dispatch_after is called with a NULL queue.
-
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-int main(int argc, const char *argv[]) {
- fprintf(stderr, "start\n");
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), NULL, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetMain());
- });
- });
- CFRunLoopRun();
-
- fprintf(stderr, "done\n");
- return 0;
-}
-
-// CHECK: start
-// CHECK: done
diff --git a/test/tsan/Darwin/norace-objcxx-run-time.mm b/test/tsan/Darwin/norace-objcxx-run-time.mm
index 1de431a076c7..ee76ec155cb4 100644
--- a/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ b/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation %darwin_min_target_with_full_runtime_arc_support
// RUN: %run %t 2>&1 | FileCheck %s
// Check that we do not report races between:
diff --git a/test/tsan/Darwin/objc-synchronize-tagged.mm b/test/tsan/Darwin/objc-synchronize-tagged.mm
new file mode 100644
index 000000000000..ab0af46ec4af
--- /dev/null
+++ b/test/tsan/Darwin/objc-synchronize-tagged.mm
@@ -0,0 +1,62 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+NSString *tagged_string = nil;
+
+@interface MyClass : NSObject {
+ long field;
+}
+@property(nonatomic, readonly) long value;
+@end
+
+dispatch_group_t group;
+
+@implementation MyClass
+
+- (void)start {
+ dispatch_queue_t q = dispatch_queue_create(NULL, NULL);
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ for (int i = 0; i < 10; i++) {
+ dispatch_async(q, ^{
+ @synchronized(tagged_string) {
+ self->field = i;
+ }
+ });
+ }
+ });
+}
+
+- (long)value {
+ @synchronized(tagged_string) {
+ return self->field;
+ }
+}
+
+- (void)dealloc {
+ dispatch_group_leave(group);
+}
+
+@end
+
+int main() {
+ tagged_string = [NSString stringWithFormat:@"%s", "abc"];
+ uintptr_t tagged_string_bits = (uintptr_t)tagged_string;
+ assert((tagged_string_bits & 0x8000000000000001ull) != 0);
+ group = dispatch_group_create();
+ @autoreleasepool {
+ for (int j = 0; j < 100; ++j) {
+ dispatch_group_enter(group);
+ MyClass *obj = [[MyClass alloc] init];
+ [obj start];
+ long x = obj.value;
+ (void)x;
+ }
+ }
+ dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
+ NSLog(@"Hello world");
+}
+
+// CHECK: Hello world
+// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/test/tsan/Darwin/objc-synchronize.mm b/test/tsan/Darwin/objc-synchronize.mm
new file mode 100644
index 000000000000..0bf06370a9b8
--- /dev/null
+++ b/test/tsan/Darwin/objc-synchronize.mm
@@ -0,0 +1,57 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+@interface MyClass : NSObject {
+ long field;
+}
+@property (nonatomic, readonly) long value;
+@end
+
+dispatch_group_t group;
+
+@implementation MyClass
+
+- (void) start {
+ dispatch_queue_t q = dispatch_queue_create(NULL, NULL);
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ for (int i = 0; i < 1000; i++) {
+ dispatch_async(q, ^{
+ @synchronized(self) {
+ self->field = i;
+ }
+ });
+ }
+ });
+}
+
+- (long) value {
+ @synchronized(self) {
+ return self->field;
+ }
+}
+
+- (void)dealloc {
+ dispatch_group_leave(group);
+}
+
+@end
+
+int main() {
+ group = dispatch_group_create();
+ @autoreleasepool {
+ for (int j = 0; j < 100; ++j) {
+ dispatch_group_enter(group);
+ MyClass *obj = [[MyClass alloc] init];
+ [obj start];
+ long x = obj.value;
+ (void)x;
+ }
+ }
+ dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
+ NSLog(@"Hello world");
+}
+
+// CHECK: Hello world
+// CHECK-NOT: WARNING: ThreadSanitizer