diff options
author | DeLesley Hutchins <delesley@google.com> | 2012-09-20 23:14:43 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2012-09-20 23:14:43 +0000 |
commit | 60ff198a22815b0aec5b96eaae977de067dcd4c1 (patch) | |
tree | 00f979ad7cde0c337029c3842786154521630cad | |
parent | 186af2de86aea41d7418158e68f96c1f8620e013 (diff) |
Thread-safety analysis: fix bug where shared trylock was treated
as exclusive.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164332 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/ThreadSafety.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/warn-thread-safety-analysis.cpp | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index fd59556665..d9ab61e753 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -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; } diff --git a/test/SemaCXX/warn-thread-safety-analysis.cpp b/test/SemaCXX/warn-thread-safety-analysis.cpp index c45adb6f0c..fa8786a957 100644 --- a/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -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 { |