1 // Check that ignore_noninstrumented_modules=1 suppresses reporting races from
2 // system libraries on OS X. There are currently false positives coming from
3 // libxpc, libdispatch, CoreFoundation and others, because these libraries use
4 // TSan-invisible atomics as synchronization.
6 // RUN: %clang_tsan %s -o %t -framework Foundation
8 // Check that without the flag, there are false positives.
9 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=0 %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
11 // With ignore_noninstrumented_modules=1, no races are reported.
12 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s
14 // With ignore_noninstrumented_modules=1, races in user's code are still reported.
15 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE
17 #import <Foundation/Foundation.h>
23 void *Thread1(void *x) {
24 barrier_wait(&barrier);
25 strcpy(global_buf, "hello world");
29 void *Thread2(void *x) {
30 strcpy(global_buf, "world hello");
31 barrier_wait(&barrier);
35 int main(int argc, char *argv[]) {
36 fprintf(stderr, "Hello world.\n");
38 // NSUserDefaults uses XPC which triggers the false positive.
39 NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
40 fprintf(stderr, "d = %p\n", d);
42 if (argc > 1 && strcmp(argv[1], "race") == 0) {
43 barrier_init(&barrier, 2);
45 pthread_create(&t[0], NULL, Thread1, NULL);
46 pthread_create(&t[1], NULL, Thread2, NULL);
47 pthread_join(t[0], NULL);
48 pthread_join(t[1], NULL);
51 fprintf(stderr, "Done.\n");
54 // CHECK: Hello world.
55 // CHECK-RACE: SUMMARY: ThreadSanitizer: data race