From e0b90771c318625e51c34c67db3f3dfbbb686df8 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Tue, 29 Jun 2021 23:51:52 +0200 Subject: [PATCH] Thread safety analysis: Rename parameters of ThreadSafetyAnalyzer::intersectAndWarn (NFC) In 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. Reviewed By: aaron.ballman, delesley Differential Revision: https://reviews.llvm.org/D104649 --- clang/lib/Analysis/ThreadSafety.cpp | 75 +++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index b09de2b..5b2c882 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1052,13 +1052,13 @@ public: 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 @@ bool ThreadSafetyAnalyzer::join(const FactEntry &A, const FactEntry &B) { /// 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() || LEK2 == LEK_LockedSomeLoopIterations) - LDat1->handleRemovalFromIntersection(FSet1Orig, FactMan, JoinLoc, LEK2, - Handler); - if (LEK2 == LEK_LockedSomePredecessors) - FSet1.removeLock(FactMan, *LDat1); + if (!ExitFact) { + if (!EntryFact->managed() || ExitLEK == LEK_LockedSomeLoopIterations) + EntryFact->handleRemovalFromIntersection(EntrySetOrig, FactMan, JoinLoc, + ExitLEK, Handler); + if (ExitLEK == LEK_LockedSomePredecessors) + EntrySet.removeLock(FactMan, *EntryFact); } } } -- 2.7.4