]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjCXX/warn-thread-safety-analysis.mm
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / SemaObjCXX / warn-thread-safety-analysis.mm
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -Wthread-safety-beta -Wno-objc-root-class %s
2
3 class __attribute__((lockable)) Lock {
4 public:
5   void Acquire() __attribute__((exclusive_lock_function())) {}
6   void Release() __attribute__((unlock_function())) {}
7 };
8
9 class __attribute__((scoped_lockable)) AutoLock {
10 public:
11   AutoLock(Lock &lock) __attribute__((exclusive_lock_function(lock)))
12   : lock_(lock) {
13     lock.Acquire();
14   }
15   ~AutoLock() __attribute__((unlock_function())) { lock_.Release(); }
16
17 private:
18   Lock &lock_;
19 };
20
21 @interface MyInterface {
22 @private
23   Lock lock_;
24   int value_;
25 }
26
27 - (void)incrementValue;
28 - (void)decrementValue;
29
30 @end
31
32 @implementation MyInterface
33
34 - (void)incrementValue {
35   AutoLock lock(lock_);
36   value_ += 1;
37 }
38
39 - (void)decrementValue {
40   lock_.Acquire(); // expected-note{{mutex acquired here}}
41   value_ -= 1;
42 } // expected-warning{{mutex 'self->lock_' is still held at the end of function}}
43
44 @end