]> granicus.if.org Git - clang/commitdiff
Thread Safety Analysis: turn off checking within trylock functions.
authorDeLesley Hutchins <delesley@google.com>
Mon, 2 Jul 2012 21:59:24 +0000 (21:59 +0000)
committerDeLesley Hutchins <delesley@google.com>
Mon, 2 Jul 2012 21:59:24 +0000 (21:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159601 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ThreadSafety.cpp
test/SemaCXX/warn-thread-safety-analysis.cpp

index fd4551b975dda22c990916f04ff9df4b9e5f8651..7406f324ae5caa37b40230bcef68270a83d57d9a 100644 (file)
@@ -1654,6 +1654,12 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
       } else if (isa<SharedLockFunctionAttr>(Attr)) {
         // Don't try to check lock functions for now
         return;
+      } else if (isa<ExclusiveTrylockFunctionAttr>(Attr)) {
+        // Don't try to check trylock functions for now
+        return;
+      } else if (isa<SharedTrylockFunctionAttr>(Attr)) {
+        // Don't try to check trylock functions for now
+        return;
       }
     }
   }
index 1c47035c2b2d4ee605d406a90a65a4fae63431c1..cda25142387180d6891a5a8c93582a9004878dd7 100644 (file)
@@ -2403,6 +2403,33 @@ void Foo::test3() {
 } // end namespace ReleasableScopedLock
 
 
+namespace TrylockFunctionTest {
+
+class Foo {
+public:
+  Mutex mu1_;
+  Mutex mu2_;
+  bool c;
+
+  bool lockBoth() EXCLUSIVE_TRYLOCK_FUNCTION(true, mu1_, mu2_);
+};
+
+bool Foo::lockBoth() {
+  if (!mu1_.TryLock())
+    return false;
+
+  mu2_.Lock();
+  if (!c) {
+    mu1_.Unlock();
+    mu2_.Unlock();
+    return false;
+  }
+
+  return true;
+}
+
+
+}  // end namespace TrylockFunctionTest