[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / test / tsan / custom_mutex5.cpp
blob6d65829e5df3cc63a08f0fecd92b0e5059f5a23f
1 // RUN: %clangxx_tsan -O1 --std=c++17 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "custom_mutex.h"
4 #include <cstddef>
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 alignas(Mutex) std::byte mu1_store[sizeof(Mutex)];
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 alignas(Mutex) std::byte mu2_store[sizeof(Mutex)];
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