[PATCH] D37963: [analyzer] PthreadLock: Don't track dead regions.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 24 07:46:23 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1484d0f12add: [analyzer] PthreadLock: Implement dead region cleanup. (authored by dergachev.a).
Herald added subscribers: Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D37963?vs=115587&id=240200#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D37963/new/

https://reviews.llvm.org/D37963

Files:
  clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -536,19 +536,24 @@
                                           CheckerContext &C) const {
   ProgramStateRef State = C.getState();
 
-  // TODO: Clean LockMap when a mutex region dies.
-
-  DestroyRetValTy TrackedSymbols = State->get<DestroyRetVal>();
-  for (DestroyRetValTy::iterator I = TrackedSymbols.begin(),
-                                 E = TrackedSymbols.end();
-       I != E; ++I) {
-    const SymbolRef Sym = I->second;
-    const MemRegion *lockR = I->first;
-    bool IsSymDead = SymReaper.isDead(Sym);
-    // Remove the dead symbol from the return value symbols map.
-    if (IsSymDead)
-      State = resolvePossiblyDestroyedMutex(State, lockR, &Sym);
+  for (auto I : State->get<DestroyRetVal>()) {
+    // Once the return value symbol dies, no more checks can be performed
+    // against it. See if the return value was checked before this point.
+    // This would remove the symbol from the map as well.
+    if (SymReaper.isDead(I.second))
+      State = resolvePossiblyDestroyedMutex(State, I.first, &I.second);
   }
+
+  for (auto I : State->get<LockMap>()) {
+    // Stop tracking dead mutex regions as well.
+    if (!SymReaper.isLiveRegion(I.first))
+      State = State->remove<LockMap>(I.first);
+  }
+
+  // TODO: We probably need to clean up the lock stack as well.
+  // It is tricky though: even if the mutex cannot be unlocked anymore,
+  // it can still participate in lock order reversal resolution.
+
   C.addTransition(State);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37963.240200.patch
Type: text/x-patch
Size: 1730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200124/bd0633af/attachment-0001.bin>


More information about the cfe-commits mailing list