aboutsummaryrefslogtreecommitdiff
path: root/test/tsan/Darwin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-14 15:38:48 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-14 15:38:48 +0000
commit5894cadf20b9970848068ff54fa4e2bfd0a9683b (patch)
treed2cbfed3f6ec3aaf3c88cfee1f6512e155cc82f8 /test/tsan/Darwin
parent3bce7d2fca357e6a1db9eff4a1c58545a3020f1b (diff)
downloadsrc-5894cadf20b9970848068ff54fa4e2bfd0a9683b.tar.gz
src-5894cadf20b9970848068ff54fa4e2bfd0a9683b.zip
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=312177 svn path=/vendor/compiler-rt/compiler-rt-release_40-r292951/; revision=312708; tag=vendor/compiler-rt/compiler-rt-release_40-r292951
Diffstat (limited to 'test/tsan/Darwin')
-rw-r--r--test/tsan/Darwin/ignore-noninstrumented.mm53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/tsan/Darwin/ignore-noninstrumented.mm b/test/tsan/Darwin/ignore-noninstrumented.mm
new file mode 100644
index 000000000000..5e4453102a9c
--- /dev/null
+++ b/test/tsan/Darwin/ignore-noninstrumented.mm
@@ -0,0 +1,53 @@
+// Check that ignore_noninstrumented_modules=1 supresses races from system libraries on OS X.
+
+// RUN: %clang_tsan %s -o %t -framework Foundation
+
+// Check that without the flag, there are false positives.
+// RUN: %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
+
+// With ignore_noninstrumented_modules=1, no races are reported.
+// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s
+
+// With ignore_noninstrumented_modules=1, races in user's code are still reported.
+// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE
+
+#import <Foundation/Foundation.h>
+
+#import "../test.h"
+
+char global_buf[64];
+
+void *Thread1(void *x) {
+ barrier_wait(&barrier);
+ strcpy(global_buf, "hello world");
+ return NULL;
+}
+
+void *Thread2(void *x) {
+ strcpy(global_buf, "world hello");
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main(int argc, char *argv[]) {
+ fprintf(stderr, "Hello world.\n");
+
+ // NSUserDefaults uses XPC which triggers the false positive.
+ NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
+ fprintf(stderr, "d = %p\n", d);
+
+ if (argc > 1 && strcmp(argv[1], "race") == 0) {
+ barrier_init(&barrier, 2);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, NULL);
+ pthread_create(&t[1], NULL, Thread2, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ }
+
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK-RACE: SUMMARY: ThreadSanitizer: data race
+// CHECK: Done.