balazske created this revision. Herald added subscribers: martong, gamesh411, Szelethus, dkrupp. Herald added a reviewer: Szelethus. balazske requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
It is possible that an entry in 'DestroyRetVal' lives longer than an entry in 'LockMap' if not removed at checkDeadSymbols. The added test case demonstrates this. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98504 Files: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp clang/test/Analysis/pthreadlock.c Index: clang/test/Analysis/pthreadlock.c =================================================================== --- clang/test/Analysis/pthreadlock.c +++ clang/test/Analysis/pthreadlock.c @@ -513,3 +513,9 @@ fake_system_function(); pthread_mutex_lock(pmtx); // expected-warning{{This lock has already been acquired}} } + +void nocrash1(pthread_mutex_t *mutex) { + int ret = pthread_mutex_destroy(mutex); + if (ret == 0) // no crash + ; +} Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp @@ -646,8 +646,10 @@ for (auto I : State->get<LockMap>()) { // Stop tracking dead mutex regions as well. - if (!SymReaper.isLiveRegion(I.first)) + if (!SymReaper.isLiveRegion(I.first)) { State = State->remove<LockMap>(I.first); + State = State->remove<DestroyRetVal>(I.first); + } } // TODO: We probably need to clean up the lock stack as well.
Index: clang/test/Analysis/pthreadlock.c =================================================================== --- clang/test/Analysis/pthreadlock.c +++ clang/test/Analysis/pthreadlock.c @@ -513,3 +513,9 @@ fake_system_function(); pthread_mutex_lock(pmtx); // expected-warning{{This lock has already been acquired}} } + +void nocrash1(pthread_mutex_t *mutex) { + int ret = pthread_mutex_destroy(mutex); + if (ret == 0) // no crash + ; +} Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp @@ -646,8 +646,10 @@ for (auto I : State->get<LockMap>()) { // Stop tracking dead mutex regions as well. - if (!SymReaper.isLiveRegion(I.first)) + if (!SymReaper.isLiveRegion(I.first)) { State = State->remove<LockMap>(I.first); + State = State->remove<DestroyRetVal>(I.first); + } } // TODO: We probably need to clean up the lock stack as well.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits