• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Check that ignore_interceptors_accesses=1 supresses 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: %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_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_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
21long global;
22
23void *Thread1(void *x) {
24  barrier_wait(&barrier);
25  global = 42;
26  return NULL;
27}
28
29void *Thread2(void *x) {
30  global = 43;
31  barrier_wait(&barrier);
32  return NULL;
33}
34
35int 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.
56