llvm-project/clang/test/SemaTemplate/warn-thread-safety-analysis.cpp
Richard Trieu b402580616 Fix some handling of AST nodes with diagnostics.
The diagnostic system for Clang can already handle many AST nodes.  Instead
of converting them to strings first, just hand the AST node directly to
the diagnostic system and let it handle the output.  Minor changes in some
diagnostic output.

llvm-svn: 328688
2018-03-28 04:16:13 +00:00

31 lines
937 B
C++

// RUN: %clang_cc1 -std=c++11 %s -verify -Wthread-safety-analysis
class Mutex {
public:
void Lock() __attribute__((exclusive_lock_function()));
void Unlock() __attribute__((unlock_function()));
};
class A {
public:
Mutex mu1, mu2;
void foo() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {}
template <class T> void bar() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {
foo();
}
};
void f() {
A a;
a.mu1.Lock();
a.mu2.Lock();
a.bar<int>();
a.mu2.Unlock();
a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}}
a.mu1.Unlock();
a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu1' exclusively}} \
expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}}
}