brintos

brintos / llvm-project-archived public Read only

0
0
Text · 999 B · 68a6761 Raw
35 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s2#include "test.h"3 4pthread_mutex_t mtx;5 6__attribute__((noinline)) void Func1() {7  pthread_mutex_lock(&mtx);8  __tsan_check_no_mutexes_held();9  pthread_mutex_unlock(&mtx);10}11 12__attribute__((noinline)) void Func2() {13  pthread_mutex_lock(&mtx);14  pthread_mutex_unlock(&mtx);15  __tsan_check_no_mutexes_held();16}17 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 context26// 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{{.*}}Func133 34// CHECK-NOT: SUMMARY: ThreadSanitizer: mutex held in the wrong context {{.*}}mutex_held_wrong_context.cpp{{.*}}Func235