]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/tsan/Darwin/ignored-interceptors.mm
Vendor import of compiler-rt trunk r338536:
[FreeBSD/FreeBSD.git] / test / tsan / Darwin / ignored-interceptors.mm
1 // Check that ignore_interceptors_accesses=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.
5
6 // RUN: %clang_tsan %s -o %t -framework Foundation
7
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
10
11 // With ignore_interceptors_accesses=1, no races are reported.
12 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
13
14 // With ignore_interceptors_accesses=1, races in user's code are still reported.
15 // RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE
16
17 #import <Foundation/Foundation.h>
18
19 #import "../test.h"
20
21 long global;
22
23 void *Thread1(void *x) {
24   barrier_wait(&barrier);
25   global = 42;
26   return NULL;
27 }
28
29 void *Thread2(void *x) {
30   global = 43;
31   barrier_wait(&barrier);
32   return NULL;
33 }
34
35 int main(int argc, char *argv[]) {
36   fprintf(stderr, "Hello world.\n");
37   
38   // NSUserDefaults uses XPC which triggers the false positive.
39   NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
40
41   if (argc > 1 && strcmp(argv[1], "race") == 0) {
42     barrier_init(&barrier, 2);
43     pthread_t t[2];
44     pthread_create(&t[0], NULL, Thread1, NULL);
45     pthread_create(&t[1], NULL, Thread2, NULL);
46     pthread_join(t[0], NULL);
47     pthread_join(t[1], NULL);
48   }
49
50   fprintf(stderr, "Done.\n");
51 }
52
53 // CHECK: Hello world.
54 // CHECK-RACE: SUMMARY: ThreadSanitizer: data race
55 // CHECK: Done.