[PATCH] D98747: Thread safety analysis: Don't warn about managed locks on join points
Aaron Puchert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 6 13:30:39 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfec26b186d2: Thread safety analysis: Don't warn about managed locks on join points (authored by aaronpuchert).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98747/new/
https://reviews.llvm.org/D98747
Files:
clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -2595,6 +2595,7 @@
if (c) { // test join point -- held/not held during release
rlock.Release();
}
+ // No warning on join point because the lock will be released by the scope object anyway.
}
void Foo::test3() {
@@ -2615,7 +2616,7 @@
if (c) {
rlock.Release();
}
- // no warning on join point for managed lock.
+ // No warning on join point because the lock will be released by the scope object anyway.
rlock.Release(); // expected-warning {{releasing mutex 'mu_' that was not held}}
}
@@ -2659,6 +2660,7 @@
Mutex mu;
int x GUARDED_BY(mu);
+bool b;
void print(int);
@@ -2740,6 +2742,23 @@
scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}}
}
+void lockJoin() {
+ RelockableMutexLock scope(&mu, DeferTraits{});
+ if (b)
+ scope.Lock();
+ // No warning on join point because the lock will be released by the scope object anyway.
+ x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+}
+
+void unlockJoin() {
+ RelockableMutexLock scope(&mu, DeferTraits{});
+ scope.Lock();
+ if (b)
+ scope.Unlock();
+ // No warning on join point because the lock will be released by the scope object anyway.
+ x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+}
+
void directUnlock() {
RelockableExclusiveMutexLock scope(&mu);
mu.Unlock();
@@ -2871,10 +2890,9 @@
void join() EXCLUSIVE_LOCKS_REQUIRED(mu) {
MutexUnlock scope(&mu);
- if (c) {
- scope.Lock(); // expected-note{{mutex acquired here}}
- }
- // expected-warning at +1{{mutex 'mu' is not held on every path through here}}
+ if (c)
+ scope.Lock();
+ // No warning on join point because the lock will be released by the scope object anyway.
scope.Lock();
}
Index: clang/lib/Analysis/ThreadSafety.cpp
===================================================================
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -983,7 +983,7 @@
} else {
FSet.removeLock(FactMan, !Cp);
FSet.addLock(FactMan,
- std::make_unique<LockableFactEntry>(Cp, kind, loc));
+ std::make_unique<LockableFactEntry>(Cp, kind, loc, true));
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98747.335650.patch
Type: text/x-patch
Size: 2510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210406/3687b226/attachment.bin>
More information about the cfe-commits
mailing list