]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/tsan/Darwin/ignore-noninstrumented.mm
New upstream version 1.20.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / tsan / Darwin / ignore-noninstrumented.mm
1 // Check that ignore_noninstrumented_modules=1 supresses races from system libraries on OS X.
2
3 // RUN: %clang_tsan %s -o %t -framework Foundation
4
5 // Check that without the flag, there are false positives.
6 // RUN: %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
7
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
10
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
13
14 #import <Foundation/Foundation.h>
15
16 #import "../test.h"
17
18 char global_buf[64];
19
20 void *Thread1(void *x) {
21 barrier_wait(&barrier);
22 strcpy(global_buf, "hello world");
23 return NULL;
24 }
25
26 void *Thread2(void *x) {
27 strcpy(global_buf, "world hello");
28 barrier_wait(&barrier);
29 return NULL;
30 }
31
32 int main(int argc, char *argv[]) {
33 fprintf(stderr, "Hello world.\n");
34
35 // NSUserDefaults uses XPC which triggers the false positive.
36 NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
37 fprintf(stderr, "d = %p\n", d);
38
39 if (argc > 1 && strcmp(argv[1], "race") == 0) {
40 barrier_init(&barrier, 2);
41 pthread_t t[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);
46 }
47
48 fprintf(stderr, "Done.\n");
49 }
50
51 // CHECK: Hello world.
52 // CHECK-RACE: SUMMARY: ThreadSanitizer: data race
53 // CHECK: Done.