[clang] 15624a7 - [analyzer] PthreadLock: Add more XNU rwlock unlock functions.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 24 07:43:37 PST 2020
Author: Artem Dergachev
Date: 2020-01-24T18:43:23+03:00
New Revision: 15624a7bda9d33b80aad5bf6f60aeced7626ee91
URL: https://github.com/llvm/llvm-project/commit/15624a7bda9d33b80aad5bf6f60aeced7626ee91
DIFF: https://github.com/llvm/llvm-project/commit/15624a7bda9d33b80aad5bf6f60aeced7626ee91.diff
LOG: [analyzer] PthreadLock: Add more XNU rwlock unlock functions.
Differential Revision: https://reviews.llvm.org/D37807
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator-for-pthread-lock.h
clang/test/Analysis/pthreadlock.c
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
index 1597955a604a..691169ff0ff5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -135,6 +135,8 @@ void PthreadLockChecker::checkPostStmt(const CallExpr *CE,
else if (FName == "pthread_mutex_unlock" ||
FName == "pthread_rwlock_unlock" ||
FName == "lck_mtx_unlock" ||
+ FName == "lck_rw_unlock_exclusive" ||
+ FName == "lck_rw_unlock_shared" ||
FName == "lck_rw_done")
ReleaseLock(C, CE, C.getSVal(CE->getArg(0)));
else if (FName == "pthread_mutex_destroy")
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-pthread-lock.h b/clang/test/Analysis/Inputs/system-header-simulator-for-pthread-lock.h
index bf60daa4d732..546bc6c3de81 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-pthread-lock.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-pthread-lock.h
@@ -15,6 +15,10 @@ typedef struct {
void *foo;
} lck_grp_t;
+typedef struct {
+ void *foo;
+} lck_rw_t;
+
typedef pthread_mutex_t lck_mtx_t;
extern int pthread_mutex_lock(pthread_mutex_t *);
@@ -28,3 +32,8 @@ extern void lck_mtx_lock(lck_mtx_t *);
extern void lck_mtx_unlock(lck_mtx_t *);
extern boolean_t lck_mtx_try_lock(lck_mtx_t *);
extern void lck_mtx_destroy(lck_mtx_t *lck, lck_grp_t *grp);
+
+extern void lck_rw_lock_exclusive(lck_rw_t *lck);
+extern void lck_rw_unlock_exclusive(lck_rw_t *lck);
+extern void lck_rw_lock_shared(lck_rw_t *lck);
+extern void lck_rw_unlock_shared(lck_rw_t *lck);
diff --git a/clang/test/Analysis/pthreadlock.c b/clang/test/Analysis/pthreadlock.c
index 56a92d7d4d92..9f95241e6dd7 100644
--- a/clang/test/Analysis/pthreadlock.c
+++ b/clang/test/Analysis/pthreadlock.c
@@ -8,6 +8,7 @@ pthread_mutex_t mtx1, mtx2;
pthread_mutex_t *pmtx;
lck_mtx_t lck1, lck2;
lck_grp_t grp1;
+lck_rw_t rw;
#define NULL 0
@@ -213,6 +214,13 @@ void ok28(void) {
}
}
+void ok29(void) {
+ lck_rw_lock_shared(&rw);
+ lck_rw_unlock_shared(&rw);
+ lck_rw_lock_exclusive(&rw); // no-warning
+ lck_rw_unlock_exclusive(&rw); // no-warning
+}
+
void
bad1(void)
{
@@ -471,3 +479,10 @@ void bad31(void) {
if (ret != 0)
pthread_mutex_lock(&mtx1);
}
+
+void bad32(void) {
+ lck_rw_lock_shared(&rw);
+ lck_rw_unlock_exclusive(&rw); // FIXME: warn - should be shared?
+ lck_rw_lock_exclusive(&rw);
+ lck_rw_unlock_shared(&rw); // FIXME: warn - should be exclusive?
+}
More information about the cfe-commits
mailing list