diff options
Diffstat (limited to 'test/Analysis/pthreadlock.c')
| -rw-r--r-- | test/Analysis/pthreadlock.c | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/test/Analysis/pthreadlock.c b/test/Analysis/pthreadlock.c index b904774245114..2a59e0ffe98ac 100644 --- a/test/Analysis/pthreadlock.c +++ b/test/Analysis/pthreadlock.c @@ -6,17 +6,31 @@ typedef struct { void *foo; } pthread_mutex_t; +typedef struct { + void *foo; +} pthread_mutexattr_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 pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr); 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; + +#define NULL 0 void ok1(void) @@ -69,6 +83,107 @@ ok7(void) } void +ok8(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_lock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning +} + +void +ok9(void) +{ + pthread_mutex_unlock(&mtx1); // no-warning + if (pthread_mutex_trylock(&mtx1) == 0) // no-warning + pthread_mutex_unlock(&mtx1); // no-warning +} + +void +ok10(void) +{ + if (pthread_mutex_trylock(&mtx1) != 0) // no-warning + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning +} + +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 +ok16(void) +{ + pthread_mutex_init(&mtx1, NULL); // no-warning +} + +void +ok17(void) +{ + pthread_mutex_init(&mtx1, NULL); // no-warning + pthread_mutex_init(&mtx2, NULL); // no-warning +} + +void +ok18(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // no-warning +} + +void +ok19(void) +{ + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // no-warning + pthread_mutex_destroy(&mtx2); // no-warning + pthread_mutex_init(&mtx2, NULL); // no-warning +} + +void +ok20(void) +{ + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // no-warning + pthread_mutex_destroy(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // no-warning +} + +void bad1(void) { pthread_mutex_lock(&mtx1); // no-warning @@ -135,3 +250,151 @@ bad8(void) lck_mtx_lock(&lck2); // no-warning lck_mtx_unlock(&lck1); // expected-warning{{This was not the most recently acquired lock}} } + +void +bad9(void) +{ + lck_mtx_unlock(&lck1); // no-warning + lck_mtx_unlock(&lck1); // expected-warning{{This lock has already been unlocked}} +} + +void +bad10(void) +{ + lck_mtx_lock(&lck1); // no-warning + lck_mtx_unlock(&lck1); // no-warning + lck_mtx_unlock(&lck1); // expected-warning{{This lock has already been unlocked}} +} + +static void +bad11_sub(pthread_mutex_t *lock) +{ + lck_mtx_unlock(lock); // expected-warning{{This lock has already been unlocked}} +} + +void +bad11(int i) +{ + lck_mtx_lock(&lck1); // no-warning + lck_mtx_unlock(&lck1); // no-warning + if (i < 5) + bad11_sub(&lck1); +} + +void +bad12(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been unlocked}} +} + +void +bad13(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_lock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx1); // expected-warning{{This lock has already been unlocked}} +} + +void +bad14(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_lock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_unlock(&mtx2); // expected-warning{{This lock has already been unlocked}} +} + +void +bad15(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_lock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx2); // no-warning + pthread_mutex_unlock(&mtx1); // no-warning + 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}} +} + +void +bad24(void) +{ + pthread_mutex_init(&mtx1, NULL); // no-warning + pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock has already been initialized}} +} + +void +bad25(void) +{ + pthread_mutex_lock(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock is still being held}} +} + +void +bad26(void) +{ + pthread_mutex_unlock(&mtx1); // no-warning + pthread_mutex_init(&mtx1, NULL); // expected-warning{{This lock has already been initialized}} +} |
