Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / custom_mutex3.cpp
blob6e99926adbca19f6123b18b537f0df682fbdc9c6
1 // RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t
2 // RUN: %env_tsan_opts=report_destroy_locked=0 %run %t 2>&1 | FileCheck %s
3 #include "custom_mutex.h"
5 // Regression test for a bug.
6 // Thr1 destroys a locked mutex, previously such mutex was not removed from
7 // sync map and as the result subsequent uses of a mutex located at the same
8 // address caused false race reports.
10 Mutex mu(false, __tsan_mutex_write_reentrant);
11 long data;
13 void *thr1(void *arg) {
14 mu.Lock();
15 mu.~Mutex();
16 new(&mu) Mutex(true, __tsan_mutex_write_reentrant);
17 return 0;
20 void *thr2(void *arg) {
21 barrier_wait(&barrier);
22 mu.Lock();
23 data++;
24 mu.Unlock();
25 return 0;
28 int main() {
29 barrier_init(&barrier, 2);
30 pthread_t th;
31 pthread_create(&th, 0, thr1, 0);
32 pthread_join(th, 0);
34 barrier_init(&barrier, 2);
35 pthread_create(&th, 0, thr2, 0);
36 mu.Lock();
37 data++;
38 mu.Unlock();
39 barrier_wait(&barrier);
40 pthread_join(th, 0);
41 fprintf(stderr, "DONE\n");
42 return 0;
45 // CHECK-NOT: WARNING: ThreadSanitizer: data race
46 // CHECK: DONE