llvm-project
49 строк · 1.3 Кб
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
10int Global;
11
12void *Thread1(void *x) {
13barrier_wait(&barrier);
14// CHECK: ThreadSanitizer: data race
15// CHECK: Write of size 4
16// CHECK: #0 Thread1{{.*}}ignorelist2.cpp:[[@LINE+1]]
17Global++;
18return NULL;
19}
20
21__attribute__((noinline)) void TouchGlobal() {
22// CHECK: Previous write of size 4
23// CHECK: #0 TouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
24Global--;
25}
26
27__attribute__((noinline)) void CallTouchGlobal() {
28// CHECK: #1 CallTouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
29TouchGlobal();
30}
31
32void *Ignorelisted_Thread2(void *x) {
33Global--;
34// CHECK: #2 Ignorelisted_Thread2{{.*}}ignorelist2.cpp:[[@LINE+1]]
35CallTouchGlobal();
36barrier_wait(&barrier);
37return NULL;
38}
39
40int main() {
41barrier_init(&barrier, 2);
42pthread_t t[2];
43pthread_create(&t[0], NULL, Thread1, NULL);
44pthread_create(&t[1], NULL, Ignorelisted_Thread2, NULL);
45pthread_join(t[0], NULL);
46pthread_join(t[1], NULL);
47fprintf(stderr, "PASS\n");
48return 0;
49}
50