[clang] d21e1b7 - Thread safety analysis: Eliminate parameter from intersectAndWarn (NFC)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Thu May 6 14:08:31 PDT 2021
Author: Aaron Puchert
Date: 2021-05-06T23:07:42+02:00
New Revision: d21e1b79ff7d40bca537c30da706e31e48483f21
URL: https://github.com/llvm/llvm-project/commit/d21e1b79ff7d40bca537c30da706e31e48483f21
DIFF: https://github.com/llvm/llvm-project/commit/d21e1b79ff7d40bca537c30da706e31e48483f21.diff
LOG: Thread safety analysis: Eliminate parameter from intersectAndWarn (NFC)
We were modifying precisely when intersecting the lock sets of multiple
predecessors without back edge. That's no coincidence: we can't modify
on back edges, it doesn't make sense to modify at the end of a function,
and otherwise we always want to intersect on forward edges, because we
can build a new lock set for those.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D101755
Added:
Modified:
clang/lib/Analysis/ThreadSafety.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index 4377fc58a1d55..83410ebc2cae3 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1051,14 +1051,12 @@ class ThreadSafetyAnalyzer {
const CFGBlock *CurrBlock);
void intersectAndWarn(FactSet &FSet1, const FactSet &FSet2,
- SourceLocation JoinLoc,
- LockErrorKind LEK1, LockErrorKind LEK2,
- bool Modify=true);
+ SourceLocation JoinLoc, LockErrorKind LEK1,
+ LockErrorKind LEK2);
void intersectAndWarn(FactSet &FSet1, const FactSet &FSet2,
- SourceLocation JoinLoc, LockErrorKind LEK1,
- bool Modify=true) {
- intersectAndWarn(FSet1, FSet2, JoinLoc, LEK1, LEK1, Modify);
+ SourceLocation JoinLoc, LockErrorKind LEK1) {
+ intersectAndWarn(FSet1, FSet2, JoinLoc, LEK1, LEK1);
}
void runAnalysis(AnalysisDeclContext &AC);
@@ -2206,8 +2204,7 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
const FactSet &FSet2,
SourceLocation JoinLoc,
LockErrorKind LEK1,
- LockErrorKind LEK2,
- bool Modify) {
+ LockErrorKind LEK2) {
FactSet FSet1Orig = FSet1;
// Find locks in FSet2 that conflict or are not in FSet1, and warn.
@@ -2220,11 +2217,13 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
if (LDat1.kind() != LDat2.kind()) {
Handler.handleExclusiveAndShared("mutex", LDat2.toString(), LDat2.loc(),
LDat1.loc());
- if (Modify && LDat1.kind() != LK_Exclusive) {
+ if (LEK1 == LEK_LockedSomePredecessors &&
+ LDat1.kind() != LK_Exclusive) {
// Take the exclusive lock, which is the one in FSet2.
*Iter1 = Fact;
}
- } else if (Modify && LDat1.asserted() && !LDat2.asserted()) {
+ } else if (LEK1 == LEK_LockedSomePredecessors && LDat1.asserted() &&
+ !LDat2.asserted()) {
// The non-asserted lock in FSet2 is the one we want to track.
*Iter1 = Fact;
}
@@ -2242,7 +2241,7 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
if (!LDat2) {
LDat1->handleRemovalFromIntersection(FSet1Orig, FactMan, JoinLoc, LEK2,
Handler);
- if (Modify)
+ if (LEK2 == LEK_LockedSomePredecessors)
FSet1.removeLock(FactMan, *LDat1);
}
}
@@ -2469,8 +2468,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
// Do not update EntrySet.
intersectAndWarn(
CurrBlockInfo->EntrySet, PrevLockset, PrevBlockInfo->ExitLoc,
- IsLoop ? LEK_LockedSomeLoopIterations : LEK_LockedSomePredecessors,
- !IsLoop);
+ IsLoop ? LEK_LockedSomeLoopIterations : LEK_LockedSomePredecessors);
}
}
@@ -2518,10 +2516,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
CFGBlock *FirstLoopBlock = *SI;
CFGBlockInfo *PreLoop = &BlockInfo[FirstLoopBlock->getBlockID()];
CFGBlockInfo *LoopEnd = &BlockInfo[CurrBlockID];
- intersectAndWarn(LoopEnd->ExitSet, PreLoop->EntrySet,
- PreLoop->EntryLoc,
- LEK_LockedSomeLoopIterations,
- false);
+ intersectAndWarn(LoopEnd->ExitSet, PreLoop->EntrySet, PreLoop->EntryLoc,
+ LEK_LockedSomeLoopIterations);
}
}
@@ -2549,11 +2545,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
ExpectedExitSet.removeLock(FactMan, Lock);
// FIXME: Should we call this function for all blocks which exit the function?
- intersectAndWarn(ExpectedExitSet, Final->ExitSet,
- Final->ExitLoc,
- LEK_LockedAtEndOfFunction,
- LEK_NotLockedAtEndOfFunction,
- false);
+ intersectAndWarn(ExpectedExitSet, Final->ExitSet, Final->ExitLoc,
+ LEK_LockedAtEndOfFunction, LEK_NotLockedAtEndOfFunction);
Handler.leaveFunction(CurrentFunction);
}
More information about the cfe-commits
mailing list