Richard Smith | 33bddbd | 2018-01-04 23:42:29 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 %s -verify -Wthread-safety-analysis |
| 2 | |
| 3 | class Mutex { |
| 4 | public: |
| 5 | void Lock() __attribute__((exclusive_lock_function())); |
| 6 | void Unlock() __attribute__((unlock_function())); |
| 7 | }; |
| 8 | |
| 9 | class A { |
| 10 | public: |
| 11 | Mutex mu1, mu2; |
| 12 | |
| 13 | void foo() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {} |
| 14 | |
| 15 | template <class T> void bar() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) { |
| 16 | foo(); |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | void f() { |
| 21 | A a; |
| 22 | a.mu1.Lock(); |
| 23 | a.mu2.Lock(); |
| 24 | a.bar<int>(); |
| 25 | a.mu2.Unlock(); |
Richard Trieu | b402580 | 2018-03-28 04:16:13 +0000 | [diff] [blame] | 26 | a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}} |
Richard Smith | 33bddbd | 2018-01-04 23:42:29 +0000 | [diff] [blame] | 27 | a.mu1.Unlock(); |
Richard Trieu | b402580 | 2018-03-28 04:16:13 +0000 | [diff] [blame] | 28 | a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu1' exclusively}} \ |
| 29 | expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}} |
Richard Smith | 33bddbd | 2018-01-04 23:42:29 +0000 | [diff] [blame] | 30 | } |