[clang] 572fe08 - Thread safety analysis: Simplify intersectAndWarn (NFC)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 23 14:21:19 PDT 2021
Author: Aaron Puchert
Date: 2021-04-23T23:19:15+02:00
New Revision: 572fe087765626529d63eaaefb2e1c5ba277f756
URL: https://github.com/llvm/llvm-project/commit/572fe087765626529d63eaaefb2e1c5ba277f756
DIFF: https://github.com/llvm/llvm-project/commit/572fe087765626529d63eaaefb2e1c5ba277f756.diff
LOG: Thread safety analysis: Simplify intersectAndWarn (NFC)
Instead of conditionally overwriting a nullptr and then branching on its
nullness, just branch directly on the original condition. Then we can
make both pointers (non-null) references instead.
Added:
Modified:
clang/lib/Analysis/ThreadSafety.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index 00678c7129a3..cbb992f40c32 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2207,27 +2207,25 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
// Find locks in FSet2 that conflict or are not in FSet1, and warn.
for (const auto &Fact : FSet2) {
- const FactEntry *LDat1 = nullptr;
- const FactEntry *LDat2 = &FactMan[Fact];
- FactSet::iterator Iter1 = FSet1.findLockIter(FactMan, *LDat2);
- if (Iter1 != FSet1.end()) LDat1 = &FactMan[*Iter1];
-
- if (LDat1) {
- if (LDat1->kind() != LDat2->kind()) {
- Handler.handleExclusiveAndShared("mutex", LDat2->toString(),
- LDat2->loc(), LDat1->loc());
- if (Modify && LDat1->kind() != LK_Exclusive) {
+ const FactEntry &LDat2 = FactMan[Fact];
+
+ FactSet::iterator Iter1 = FSet1.findLockIter(FactMan, LDat2);
+ if (Iter1 != FSet1.end()) {
+ const FactEntry &LDat1 = FactMan[*Iter1];
+ if (LDat1.kind() != LDat2.kind()) {
+ Handler.handleExclusiveAndShared("mutex", LDat2.toString(), LDat2.loc(),
+ LDat1.loc());
+ if (Modify && 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 (Modify && LDat1.asserted() && !LDat2.asserted()) {
// The non-asserted lock in FSet2 is the one we want to track.
*Iter1 = Fact;
}
} else {
- LDat2->handleRemovalFromIntersection(FSet2, FactMan, JoinLoc, LEK1,
- Handler);
+ LDat2.handleRemovalFromIntersection(FSet2, FactMan, JoinLoc, LEK1,
+ Handler);
}
}
More information about the cfe-commits
mailing list