1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include "test.h" 3 4 pthread_mutex_t mtx; 5 Func1()6__attribute__((noinline)) void Func1() { 7 pthread_mutex_lock(&mtx); 8 __tsan_check_no_mutexes_held(); 9 pthread_mutex_unlock(&mtx); 10 } 11 Func2()12__attribute__((noinline)) void Func2() { 13 pthread_mutex_lock(&mtx); 14 pthread_mutex_unlock(&mtx); 15 __tsan_check_no_mutexes_held(); 16 } 17 main()18int main() { 19 pthread_mutex_init(&mtx, NULL); 20 Func1(); 21 Func2(); 22 return 0; 23 } 24 25 // CHECK: WARNING: ThreadSanitizer: mutex held in the wrong context 26 // CHECK: {{.*}}__tsan_check_no_mutexes_held{{.*}} 27 // CHECK: {{.*}}Func1{{.*}} 28 // CHECK: {{.*}}main{{.*}} 29 // CHECK: Mutex {{.*}} created at: 30 // CHECK: {{.*}}pthread_mutex_init{{.*}} 31 // CHECK: {{.*}}main{{.*}} 32 // CHECK: SUMMARY: ThreadSanitizer: mutex held in the wrong context {{.*}}mutex_held_wrong_context.cpp{{.*}}Func1 33 34 // CHECK-NOT: SUMMARY: ThreadSanitizer: mutex held in the wrong context {{.*}}mutex_held_wrong_context.cpp{{.*}}Func2 35