diff options
Diffstat (limited to 'test/Sema/warn-thread-safety-analysis.c')
-rw-r--r-- | test/Sema/warn-thread-safety-analysis.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/test/Sema/warn-thread-safety-analysis.c b/test/Sema/warn-thread-safety-analysis.c index 1918aceee6da..6d41e40d303f 100644 --- a/test/Sema/warn-thread-safety-analysis.c +++ b/test/Sema/warn-thread-safety-analysis.c @@ -1,4 +1,4 @@ -// RUN: %clang -fsyntax-only -verify -Wthread-safety -Wthread-safety-beta -fcxx-exceptions %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -Wthread-safety-beta %s #define LOCKABLE __attribute__ ((lockable)) #define SCOPED_LOCKABLE __attribute__ ((scoped_lockable)) @@ -31,15 +31,12 @@ struct Foo { struct Mutex *mu_; }; -// Define mutex lock/unlock functions. -void mutex_exclusive_lock(struct Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) { -} - -void mutex_shared_lock(struct Mutex *mu) SHARED_LOCK_FUNCTION(mu) { -} - -void mutex_unlock(struct Mutex *mu) UNLOCK_FUNCTION(mu) { -} +// Declare mutex lock/unlock functions. +void mutex_exclusive_lock(struct Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu); +void mutex_shared_lock(struct Mutex *mu) SHARED_LOCK_FUNCTION(mu); +void mutex_unlock(struct Mutex *mu) UNLOCK_FUNCTION(mu); +void mutex_shared_unlock(struct Mutex *mu) __attribute__((release_shared_capability(mu))); +void mutex_exclusive_unlock(struct Mutex *mu) __attribute__((release_capability(mu))); // Define global variables. struct Mutex mu1; @@ -77,14 +74,14 @@ int get_value(int *p) SHARED_LOCKS_REQUIRED(foo_.mu_){ int main() { - Foo_fun1(1); // expected-warning{{calling function 'Foo_fun1' requires shared lock on 'mu2'}} \ - expected-warning{{calling function 'Foo_fun1' requires exclusive lock on 'mu1'}} + Foo_fun1(1); // expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu2'}} \ + expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu1' exclusively}} mutex_exclusive_lock(&mu1); mutex_shared_lock(&mu2); Foo_fun1(1); - mutex_shared_lock(&mu1); // expected-warning{{locking 'mu1' that is already locked}} + mutex_shared_lock(&mu1); // expected-warning{{acquiring mutex 'mu1' that is already held}} mutex_unlock(&mu1); mutex_unlock(&mu2); mutex_shared_lock(&mu1); @@ -98,13 +95,13 @@ int main() { mutex_unlock(&mu1); mutex_exclusive_lock(&mu1); - Foo_func3(4); // expected-warning{{cannot call function 'Foo_func3' while mutex 'mu1' is locked}} + Foo_func3(4); // expected-warning{{cannot call function 'Foo_func3' while mutex 'mu1' is held}} mutex_unlock(&mu1); Foo_func3(5); - set_value(&a_, 0); // expected-warning{{calling function 'setA' requires exclusive lock on 'foo_.mu_'}} - get_value(b_); // expected-warning{{calling function 'getB' requires shared lock on 'foo_.mu_'}} + set_value(&a_, 0); // expected-warning{{calling function 'set_value' requires holding mutex 'foo_.mu_' exclusively}} + get_value(b_); // expected-warning{{calling function 'get_value' requires holding mutex 'foo_.mu_'}} mutex_exclusive_lock(foo_.mu_); set_value(&a_, 1); mutex_unlock(foo_.mu_); @@ -112,12 +109,20 @@ int main() { (void)(get_value(b_) == 1); mutex_unlock(foo_.mu_); - c_ = 0; // expected-warning{{writing variable 'c_' requires locking any mutex exclusively}} - (void)(*d_ == 0); // expected-warning{{reading the value pointed to by 'd_' requires locking any mutex}} + c_ = 0; // expected-warning{{writing variable 'c_' requires holding any mutex exclusively}} + (void)(*d_ == 0); // expected-warning{{reading the value pointed to by 'd_' requires holding any mutex}} mutex_exclusive_lock(foo_.mu_); c_ = 1; (void)(*d_ == 1); mutex_unlock(foo_.mu_); + mutex_exclusive_lock(&mu1); + mutex_shared_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using shared access, expected exclusive access}} + mutex_exclusive_unlock(&mu1); + + mutex_shared_lock(&mu1); + mutex_exclusive_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using exclusive access, expected shared access}} + mutex_shared_unlock(&mu1); + return 0; } |