From: DeLesley Hutchins Date: Thu, 20 Sep 2012 23:14:43 +0000 (+0000) Subject: Thread-safety analysis: fix bug where shared trylock was treated X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60ff198a22815b0aec5b96eaae977de067dcd4c1;p=clang 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 --- 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(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 {