[PATCH] D104649: Thread safety analysis: Rename parameters of ThreadSafetyAnalyzer::intersectAndWarn (NFC)

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 21 08:11:43 PDT 2021


aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, delesley.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In D104261 <https://reviews.llvm.org/D104261> we made the parameters' meaning slightly more specific, this
changes their names accordingly. In all uses we're building a new lock
set by intersecting existing locksets. The first (modifiable) argument
is the new lock set being built, the second (non-modifiable) argument is
the exit set of a preceding block.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104649

Files:
  clang/lib/Analysis/ThreadSafety.cpp


Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1052,13 +1052,13 @@
 
   bool join(const FactEntry &a, const FactEntry &b);
 
-  void intersectAndWarn(FactSet &FSet1, const FactSet &FSet2,
-                        SourceLocation JoinLoc, LockErrorKind LEK1,
-                        LockErrorKind LEK2);
+  void intersectAndWarn(FactSet &EntrySet, const FactSet &ExitSet,
+                        SourceLocation JoinLoc, LockErrorKind EntryLEK,
+                        LockErrorKind ExitLEK);
 
-  void intersectAndWarn(FactSet &FSet1, const FactSet &FSet2,
-                        SourceLocation JoinLoc, LockErrorKind LEK1) {
-    intersectAndWarn(FSet1, FSet2, JoinLoc, LEK1, LEK1);
+  void intersectAndWarn(FactSet &EntrySet, const FactSet &ExitSet,
+                        SourceLocation JoinLoc, LockErrorKind LEK) {
+    intersectAndWarn(EntrySet, ExitSet, JoinLoc, LEK, LEK);
   }
 
   void runAnalysis(AnalysisDeclContext &AC);
@@ -2219,43 +2219,44 @@
 /// are the same. In the event of a difference, we use the intersection of these
 /// two locksets at the start of D.
 ///
-/// \param FSet1 The first lockset.
-/// \param FSet2 The second lockset.
+/// \param EntrySet A lockset for entry into a (possibly new) block.
+/// \param ExitSet The lockset on exiting a preceding block.
 /// \param JoinLoc The location of the join point for error reporting
-/// \param LEK1 The error message to report if a mutex is missing from LSet1
-/// \param LEK2 The error message to report if a mutex is missing from Lset2
-void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
-                                            const FactSet &FSet2,
+/// \param EntryLEK The warning if a mutex is missing from \p EntrySet.
+/// \param ExitLEK The warning if a mutex is missing from \p ExitSet.
+void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &EntrySet,
+                                            const FactSet &ExitSet,
                                             SourceLocation JoinLoc,
-                                            LockErrorKind LEK1,
-                                            LockErrorKind LEK2) {
-  FactSet FSet1Orig = FSet1;
-
-  // Find locks in FSet2 that conflict or are not in FSet1, and warn.
-  for (const auto &Fact : FSet2) {
-    const FactEntry &LDat2 = FactMan[Fact];
-
-    FactSet::iterator Iter1 = FSet1.findLockIter(FactMan, LDat2);
-    if (Iter1 != FSet1.end()) {
-      if (join(FactMan[*Iter1], LDat2) && LEK1 == LEK_LockedSomePredecessors)
-        *Iter1 = Fact;
-    } else if (!LDat2.managed()) {
-      LDat2.handleRemovalFromIntersection(FSet2, FactMan, JoinLoc, LEK1,
-                                          Handler);
+                                            LockErrorKind EntryLEK,
+                                            LockErrorKind ExitLEK) {
+  FactSet EntrySetOrig = EntrySet;
+
+  // Find locks in ExitSet that conflict or are not in EntrySet, and warn.
+  for (const auto &Fact : ExitSet) {
+    const FactEntry &ExitFact = FactMan[Fact];
+
+    FactSet::iterator EntryIt = EntrySet.findLockIter(FactMan, ExitFact);
+    if (EntryIt != EntrySet.end()) {
+      if (join(FactMan[*EntryIt], ExitFact) &&
+          EntryLEK == LEK_LockedSomePredecessors)
+        *EntryIt = Fact;
+    } else if (!ExitFact.managed()) {
+      ExitFact.handleRemovalFromIntersection(ExitSet, FactMan, JoinLoc,
+                                             EntryLEK, Handler);
     }
   }
 
-  // Find locks in FSet1 that are not in FSet2, and remove them.
-  for (const auto &Fact : FSet1Orig) {
-    const FactEntry *LDat1 = &FactMan[Fact];
-    const FactEntry *LDat2 = FSet2.findLock(FactMan, *LDat1);
+  // Find locks in EntrySet that are not in ExitSet, and remove them.
+  for (const auto &Fact : EntrySetOrig) {
+    const FactEntry *EntryFact = &FactMan[Fact];
+    const FactEntry *ExitFact = ExitSet.findLock(FactMan, *EntryFact);
 
-    if (!LDat2) {
-      if (!LDat1->managed() || LEK1 == LEK_LockedSomeLoopIterations)
-        LDat1->handleRemovalFromIntersection(FSet1Orig, FactMan, JoinLoc, LEK2,
-                                             Handler);
-      if (LEK2 == LEK_LockedSomePredecessors)
-        FSet1.removeLock(FactMan, *LDat1);
+    if (!ExitFact) {
+      if (!EntryFact->managed() || EntryLEK == LEK_LockedSomeLoopIterations)
+        EntryFact->handleRemovalFromIntersection(EntrySetOrig, FactMan, JoinLoc,
+                                                 ExitLEK, Handler);
+      if (ExitLEK == LEK_LockedSomePredecessors)
+        EntrySet.removeLock(FactMan, *EntryFact);
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104649.353380.patch
Type: text/x-patch
Size: 4735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210621/7cfa44b8/attachment-0001.bin>


More information about the cfe-commits mailing list