xref: /llvm-project/compiler-rt/test/tsan/default_options.cpp (revision e520800eda3d9810be6c78d8056c7e384d0ace70)
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <sanitizer/tsan_interface.h>
4 #include <stdio.h>
5 
6 #if (__APPLE__)
7 __attribute__((weak))
8 #endif
__tsan_default_options()9 extern "C" const char *__tsan_default_options() {
10   return "report_bugs=0";
11 }
12 
13 int Global;
14 
Thread1(void * x)15 void *Thread1(void *x) {
16   Global = 42;
17   return NULL;
18 }
19 
Thread2(void * x)20 void *Thread2(void *x) {
21   Global = 43;
22   return NULL;
23 }
24 
main()25 int main() {
26   pthread_t t[2];
27   pthread_create(&t[0], NULL, Thread1, NULL);
28   pthread_create(&t[1], NULL, Thread2, NULL);
29   pthread_join(t[0], NULL);
30   pthread_join(t[1], NULL);
31   fprintf(stderr, "DONE\n");
32   return 0;
33 }
34 
35 // CHECK-NOT: WARNING: ThreadSanitizer: data race
36 // CHECK: DONE
37