]> granicus.if.org Git - clang/commitdiff
Thread-safety analysis: fix bug where shared trylock was treated
authorDeLesley Hutchins <delesley@google.com>
Thu, 20 Sep 2012 23:14:43 +0000 (23:14 +0000)
committerDeLesley Hutchins <delesley@google.com>
Thu, 20 Sep 2012 23:14:43 +0000 (23:14 +0000)
as exclusive.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164332 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fd595566651b5b6b27c341a96f2eff5af374ae3e..d9ab61e75344d3bbe422f1f1f24270775b82ebd6 100644 (file)
@@ -1681,7 +1681,7 @@ void ThreadSafetyAnalyzer::getEdgeLockset(FactSet& Result,
       case attr::SharedTrylockFunction: {
         SharedTrylockFunctionAttr *A =
           cast<SharedTrylockFunctionAttr>(Attr);
-        getMutexIDs(ExclusiveLocksToAdd, A, Exp, FunDecl,
+        getMutexIDs(SharedLocksToAdd, A, Exp, FunDecl,
                     PredBlock, CurrBlock, A->getSuccessValue(), Negate);
         break;
       }
index c45adb6f0cc1b6b6f790f8ceab33761404c40252..fa8786a957fb6ff2ff6b0259392eeaedbada743b 100644 (file)
@@ -1655,6 +1655,8 @@ void bar() {
 };  // end namespace FunctionAttrTest
 
 
+namespace TryLockTest {
+
 struct TestTryLock {
   Mutex mu;
   int a GUARDED_BY(mu);
@@ -1751,8 +1753,36 @@ struct TestTryLock {
       b = !b;
     }
   }
+
+  // Test merge of exclusive trylock
+  void foo11() {
+   if (cond) {
+     if (!mu.TryLock())
+       return;
+   }
+   else {
+     mu.Lock();
+   }
+   a = 10;
+   mu.Unlock();
+  }
+
+  // Test merge of shared trylock
+  void foo12() {
+   if (cond) {
+     if (!mu.ReaderTryLock())
+       return;
+   }
+   else {
+     mu.ReaderLock();
+   }
+   int i = a;
+   mu.Unlock();
+  }
 };  // end TestTrylock
 
+} // end namespace TrylockTest
+
 
 namespace TestTemplateAttributeInstantiation {