Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / mutex_annotations.cpp
blob59fa452c0a76a9af25d9f857c3403255930e5619
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
4 // Test that a linker-initialized mutex can be created/destroyed while in use.
6 // Stub for testing, just invokes annotations.
7 // Meant to be synchronized externally with test barrier.
8 class Mutex {
9 public:
10 void Create(bool linker_initialized = false) {
11 if (linker_initialized)
12 ANNOTATE_RWLOCK_CREATE_STATIC(&state_);
13 else
14 ANNOTATE_RWLOCK_CREATE(&state_);
17 void Destroy() {
18 ANNOTATE_RWLOCK_DESTROY(&state_);
21 void Lock() {
22 ANNOTATE_RWLOCK_ACQUIRED(&state_, true);
25 void Unlock() {
26 ANNOTATE_RWLOCK_RELEASED(&state_, true);
29 private:
30 long long state_;
33 int main() {
34 Mutex m;
36 m.Lock();
37 m.Create(true);
38 m.Unlock();
40 m.Lock();
41 m.Destroy();
42 m.Unlock();
44 fprintf(stderr, "DONE\n");
45 return 0;
48 // CHECK-NOT: WARNING: ThreadSanitizer:
49 // CHECK: DONE