summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
diff options
context:
space:
mode:
authorDeLesley Hutchins <delesley@google.com>2012-07-02 22:26:29 +0000
committerDeLesley Hutchins <delesley@google.com>2012-07-02 22:26:29 +0000
commitab0d4e6cd881ae078bcba512b6dfceffc02a375b (patch)
treee45284e511270fb82bfd63c4aca544b6290b3d3b /clang/test/SemaCXX/warn-thread-safety-analysis.cpp
parenta4ee064cf361a0ad6f9d07276afb31801fa77b7a (diff)
downloadbcm5719-llvm-ab0d4e6cd881ae078bcba512b6dfceffc02a375b.tar.gz
bcm5719-llvm-ab0d4e6cd881ae078bcba512b6dfceffc02a375b.zip
Thread safety analysis: fixed bug that occurs when very silly people
use scoped_lockable without putting unlock_function on the destructor. llvm-svn: 159609
Diffstat (limited to 'clang/test/SemaCXX/warn-thread-safety-analysis.cpp')
-rw-r--r--clang/test/SemaCXX/warn-thread-safety-analysis.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index 35a2dd01214..2bf9ed40796 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -2470,3 +2470,68 @@ public:
} // end namespace UnlockBug
+namespace FoolishScopedLockableBug {
+
+class SCOPED_LOCKABLE WTF_ScopedLockable {
+public:
+ WTF_ScopedLockable(Mutex* mu) EXCLUSIVE_LOCK_FUNCTION(mu);
+
+ // have to call release() manually;
+ ~WTF_ScopedLockable();
+
+ void release() UNLOCK_FUNCTION();
+};
+
+
+class Foo {
+ Mutex mu_;
+ int a GUARDED_BY(mu_);
+ bool c;
+
+ void doSomething();
+
+ void test1() {
+ WTF_ScopedLockable wtf(&mu_);
+ wtf.release();
+ }
+
+ void test2() {
+ WTF_ScopedLockable wtf(&mu_); // expected-note {{mutex acquired here}}
+ } // expected-warning {{mutex 'mu_' is still locked at the end of function}}
+
+ void test3() {
+ if (c) {
+ WTF_ScopedLockable wtf(&mu_);
+ wtf.release();
+ }
+ }
+
+ void test4() {
+ if (c) {
+ doSomething();
+ }
+ else {
+ WTF_ScopedLockable wtf(&mu_);
+ wtf.release();
+ }
+ }
+
+ void test5() {
+ if (c) {
+ WTF_ScopedLockable wtf(&mu_); // expected-note {{mutex acquired here}}
+ }
+ } // expected-warning {{mutex 'mu_' is not locked on every path through here}}
+
+ void test6() {
+ if (c) {
+ doSomething();
+ }
+ else {
+ WTF_ScopedLockable wtf(&mu_); // expected-note {{mutex acquired here}}
+ }
+ } // expected-warning {{mutex 'mu_' is not locked on every path through here}}
+};
+
+
+} // end namespace FoolishScopedLockableBug
+
OpenPOWER on IntegriCloud