annotate compiler-rt/test/tsan/custom_mutex5.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
anatofuz
parents:
diff changeset
2 #include "custom_mutex.h"
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 #include <type_traits>
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Test that we detect the destruction of an in-use mutex when the
anatofuz
parents:
diff changeset
7 // thread annotations don't otherwise disable the check.
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 int main() {
anatofuz
parents:
diff changeset
10 std::aligned_storage<sizeof(Mutex), alignof(Mutex)>::type mu1_store;
anatofuz
parents:
diff changeset
11 Mutex* mu1 = reinterpret_cast<Mutex*>(&mu1_store);
anatofuz
parents:
diff changeset
12 new(&mu1_store) Mutex(false, 0);
anatofuz
parents:
diff changeset
13 mu1->Lock();
anatofuz
parents:
diff changeset
14 mu1->~Mutex();
anatofuz
parents:
diff changeset
15 mu1->Unlock();
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 std::aligned_storage<sizeof(Mutex), alignof(Mutex)>::type mu2_store;
anatofuz
parents:
diff changeset
18 Mutex* mu2 = reinterpret_cast<Mutex*>(&mu2_store);
anatofuz
parents:
diff changeset
19 new(&mu2_store)
anatofuz
parents:
diff changeset
20 Mutex(false, __tsan_mutex_not_static, __tsan_mutex_not_static);
anatofuz
parents:
diff changeset
21 mu2->Lock();
anatofuz
parents:
diff changeset
22 mu2->~Mutex();
anatofuz
parents:
diff changeset
23 mu2->Unlock();
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 fprintf(stderr, "DONE\n");
anatofuz
parents:
diff changeset
26 return 0;
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
anatofuz
parents:
diff changeset
30 // CHECK: main {{.*}}custom_mutex5.cpp:14
anatofuz
parents:
diff changeset
31 // CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
anatofuz
parents:
diff changeset
32 // CHECK: main {{.*}}custom_mutex5.cpp:22
anatofuz
parents:
diff changeset
33 // CHECK: DONE