1 // Test that ignorelisted functions are still contained in the stack trace.
2 
3 // RUN: echo "fun:*Ignorelisted_Thread2*" > %t.ignorelist
4 // RUN: echo "fun:*CallTouchGlobal*" >> %t.ignorelist
5 
6 // RUN: %clangxx_tsan -O1 %s -fsanitize-ignorelist=%t.ignorelist -o %t
7 // RUN: %deflake %run %t 2>&1 | FileCheck %s
8 #include "test.h"
9 
10 int Global;
11 
Thread1(void * x)12 void *Thread1(void *x) {
13   barrier_wait(&barrier);
14   // CHECK: ThreadSanitizer: data race
15   // CHECK: Write of size 4
16   // CHECK: #0 Thread1{{.*}}ignorelist2.cpp:[[@LINE+1]]
17   Global++;
18   return NULL;
19 }
20 
TouchGlobal()21 void TouchGlobal() __attribute__((noinline)) {
22   // CHECK: Previous write of size 4
23   // CHECK: #0 TouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
24   Global--;
25 }
26 
CallTouchGlobal()27 void CallTouchGlobal() __attribute__((noinline)) {
28   // CHECK: #1 CallTouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
29   TouchGlobal();
30 }
31 
Ignorelisted_Thread2(void * x)32 void *Ignorelisted_Thread2(void *x) {
33   Global--;
34   // CHECK: #2 Ignorelisted_Thread2{{.*}}ignorelist2.cpp:[[@LINE+1]]
35   CallTouchGlobal();
36   barrier_wait(&barrier);
37   return NULL;
38 }
39 
main()40 int main() {
41   barrier_init(&barrier, 2);
42   pthread_t t[2];
43   pthread_create(&t[0], NULL, Thread1, NULL);
44   pthread_create(&t[1], NULL, Ignorelisted_Thread2, NULL);
45   pthread_join(t[0], NULL);
46   pthread_join(t[1], NULL);
47   fprintf(stderr, "PASS\n");
48   return 0;
49 }
50