diff options
author | Jordan Rose <jordan_rose@apple.com> | 2014-04-01 03:40:47 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2014-04-01 03:40:47 +0000 |
commit | 7fcaa14a82960c7e33a0c7aba881f32d18060b0c (patch) | |
tree | 2880c0cb9fb2a8df8133178f2598e0e5db66b494 /clang/test/Analysis/pthreadlock.c | |
parent | 0696bb4cef7592892019b5e6c6ee9d1603843061 (diff) | |
download | bcm5719-llvm-7fcaa14a82960c7e33a0c7aba881f32d18060b0c.tar.gz bcm5719-llvm-7fcaa14a82960c7e33a0c7aba881f32d18060b0c.zip |
[analyzer] Lock checker: make sure locks aren't used after being destroyed.
Patch by Daniel Fahlgren!
llvm-svn: 205275
Diffstat (limited to 'clang/test/Analysis/pthreadlock.c')
-rw-r--r-- | clang/test/Analysis/pthreadlock.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/clang/test/Analysis/pthreadlock.c b/clang/test/Analysis/pthreadlock.c index bc7ef66353f..6a75a6e480e 100644 --- a/clang/test/Analysis/pthreadlock.c +++ b/clang/test/Analysis/pthreadlock.c @@ -6,17 +6,24 @@ typedef struct { void *foo; } pthread_mutex_t; +typedef struct { + void *foo; +} lck_grp_t; + typedef pthread_mutex_t lck_mtx_t; extern int pthread_mutex_lock(pthread_mutex_t *); extern int pthread_mutex_unlock(pthread_mutex_t *); extern int pthread_mutex_trylock(pthread_mutex_t *); +extern int pthread_mutex_destroy(pthread_mutex_t *); extern int lck_mtx_lock(lck_mtx_t *); extern int lck_mtx_unlock(lck_mtx_t *); extern int lck_mtx_try_lock(lck_mtx_t *); +extern void lck_mtx_destroy(lck_mtx_t *lck, lck_grp_t *grp); pthread_mutex_t mtx1, mtx2; lck_mtx_t lck1, lck2; +lck_grp_t grp1; void ok1(void) @@ -94,6 +101,43 @@ ok10(void) } void +ok11(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning +} + +void +ok12(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_destroy(&mtx2); // no-warning +} + +void +ok13(void) +{ + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // no-warning +} + +void +ok14(void) +{ + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_unlock(&mtx2); // no-warning + pthread_mutex_destroy(&mtx2); // no-warning +} + +void +ok15(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // no-warning +} + +void bad1(void) { pthread_mutex_lock(&mtx1); // no-warning @@ -231,3 +275,59 @@ bad15(void) pthread_mutex_lock(&mtx1); // no-warning pthread_mutex_unlock(&mtx2); // expected-warning{{This lock has already been unlocked}} } + +void +bad16(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_lock(&mtx1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad17(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad18(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad19(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // expected-warning{{This lock is still locked}} +} + +void +bad20(void) +{ + lck_mtx_destroy(&mtx1, &grp1); // no-warning + lck_mtx_lock(&mtx1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad21(void) +{ + lck_mtx_destroy(&mtx1, &grp1); // no-warning + lck_mtx_unlock(&mtx1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad22(void) +{ + lck_mtx_destroy(&mtx1, &grp1); // no-warning + lck_mtx_destroy(&mtx1, &grp1); // expected-warning{{This lock has already been destroyed}} +} + +void +bad23(void) +{ + lck_mtx_lock(&mtx1); // no-warning + lck_mtx_destroy(&mtx1, &grp1); // expected-warning{{This lock is still locked}} +} |