1 // Check that ignore_noninstrumented_modules=1 supresses races from system libraries on OS X.
3 // RUN: %clang_tsan %s -o %t -framework Foundation
5 // Check that without the flag, there are false positives.
6 // RUN: %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
8 // With ignore_noninstrumented_modules=1, no races are reported.
9 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s
11 // With ignore_noninstrumented_modules=1, races in user's code are still reported.
12 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE
14 #import <Foundation/Foundation.h>
20 void *Thread1(void *x) {
21 barrier_wait(&barrier);
22 strcpy(global_buf, "hello world");
26 void *Thread2(void *x) {
27 strcpy(global_buf, "world hello");
28 barrier_wait(&barrier);
32 int main(int argc, char *argv[]) {
33 fprintf(stderr, "Hello world.\n");
35 // NSUserDefaults uses XPC which triggers the false positive.
36 NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
37 fprintf(stderr, "d = %p\n", d);
39 if (argc > 1 && strcmp(argv[1], "race") == 0) {
40 barrier_init(&barrier, 2);
42 pthread_create(&t[0], NULL, Thread1, NULL);
43 pthread_create(&t[1], NULL, Thread2, NULL);
44 pthread_join(t[0], NULL);
45 pthread_join(t[1], NULL);
48 fprintf(stderr, "Done.\n");
51 // CHECK: Hello world.
52 // CHECK-RACE: SUMMARY: ThreadSanitizer: data race