Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / custom_mutex5.cpp
blobcb18b235e26288cace8ac7e27a7045b996d61145
1 // RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "custom_mutex.h"
4 #include <type_traits>
6 // Test that we detect the destruction of an in-use mutex when the
7 // thread annotations don't otherwise disable the check.
9 int main() {
10 std::aligned_storage<sizeof(Mutex), alignof(Mutex)>::type mu1_store;
11 Mutex* mu1 = reinterpret_cast<Mutex*>(&mu1_store);
12 new(&mu1_store) Mutex(false, 0);
13 mu1->Lock();
14 mu1->~Mutex();
15 mu1->Unlock();
17 std::aligned_storage<sizeof(Mutex), alignof(Mutex)>::type mu2_store;
18 Mutex* mu2 = reinterpret_cast<Mutex*>(&mu2_store);
19 new(&mu2_store)
20 Mutex(false, __tsan_mutex_not_static, __tsan_mutex_not_static);
21 mu2->Lock();
22 mu2->~Mutex();
23 mu2->Unlock();
25 fprintf(stderr, "DONE\n");
26 return 0;
29 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
30 // CHECK: main {{.*}}custom_mutex5.cpp:14
31 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
32 // CHECK: main {{.*}}custom_mutex5.cpp:22
33 // CHECK: DONE