]> granicus.if.org Git - clang/commitdiff
Thread Safety Analysis: new test case for lambdas
authorDeLesley Hutchins <delesley@google.com>
Wed, 12 Mar 2014 21:33:47 +0000 (21:33 +0000)
committerDeLesley Hutchins <delesley@google.com>
Wed, 12 Mar 2014 21:33:47 +0000 (21:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203720 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaCXX/warn-thread-safety-analysis.cpp

index 7c0a73327b827910ec376e819ada8ad5ed94c5e9..461bb5a1b66ab3e041f9043b9ff12e980e35af1a 100644 (file)
@@ -4335,7 +4335,8 @@ class A {
 
 }  // end namespace NonMemberCalleeICETest
 
-namespace {
+
+namespace pt_guard_attribute_type {
   int i PT_GUARDED_BY(sls_mu);  // expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
   int j PT_GUARDED_VAR;  // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
 
@@ -4346,4 +4347,34 @@ namespace {
     typedef int PT_GUARDED_BY(sls_mu) bad1;  // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
     typedef int PT_GUARDED_VAR bad2;  // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
   }
-}
+}  // end namespace pt_guard_attribute_type
+
+
+namespace ThreadAttributesOnLambdas {
+
+class Foo {
+  Mutex mu_;
+
+  void LockedFunction() EXCLUSIVE_LOCKS_REQUIRED(mu_);
+
+  void test() {
+    auto func1 = [this]() EXCLUSIVE_LOCKS_REQUIRED(mu_) {
+      LockedFunction();
+    };
+
+    auto func2 = [this]() NO_THREAD_SAFETY_ANALYSIS {
+      LockedFunction();
+    };
+
+    auto func3 = [this]() EXCLUSIVE_LOCK_FUNCTION(mu_) {
+      mu_.Lock();
+    };
+
+    func1();  // expected-warning {{calling function 'operator()' requires exclusive lock on 'mu_'}}
+    func2();
+    func3();
+    mu_.Unlock();
+  }
+};
+
+}  // end namespace ThreadAttributesOnLambdas