From fd0f11ccd51154e933fad7dfa134cb4f62c87056 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Wed, 5 Sep 2012 20:01:16 +0000 Subject: [PATCH] Thread-safety analysis: bugfix for case where a trylock occurs in an expression involving temporaries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163237 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ThreadSafety.cpp | 3 +++ test/SemaCXX/warn-thread-safety-analysis.cpp | 27 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index b89a83c881..90c407ac65 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -1532,6 +1532,9 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond, else if (const ImplicitCastExpr *CE = dyn_cast(Cond)) { return getTrylockCallExpr(CE->getSubExpr(), C, Negate); } + else if (const ExprWithCleanups* EWC = dyn_cast(Cond)) { + return getTrylockCallExpr(EWC->getSubExpr(), C, Negate); + } else if (const DeclRefExpr *DRE = dyn_cast(Cond)) { const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C); return getTrylockCallExpr(E, C, Negate); diff --git a/test/SemaCXX/warn-thread-safety-analysis.cpp b/test/SemaCXX/warn-thread-safety-analysis.cpp index 7d0d6430d9..cf378c5090 100644 --- a/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -3190,3 +3190,30 @@ void Base::bar(Inner* i) { } // end namespace LockReturnedScopeFix + +namespace TrylockWithCleanups { + +class MyString { +public: + MyString(const char* s); + ~MyString(); +}; + +struct Foo { + Mutex mu_; + int a GUARDED_BY(mu_); +}; + +Foo* GetAndLockFoo(const MyString& s) + EXCLUSIVE_TRYLOCK_FUNCTION(true, &Foo::mu_); + +static void test() { + Foo* lt = GetAndLockFoo("foo"); + if (!lt) return; + int a = lt->a; + lt->mu_.Unlock(); +} + +} + + -- 2.50.1