]> granicus.if.org Git - clang/commitdiff
Thread-safety analysis: bugfix for case where a trylock occurs in an
authorDeLesley Hutchins <delesley@google.com>
Wed, 5 Sep 2012 20:01:16 +0000 (20:01 +0000)
committerDeLesley Hutchins <delesley@google.com>
Wed, 5 Sep 2012 20:01:16 +0000 (20:01 +0000)
expression involving temporaries.

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

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

index b89a83c8817d240eb979297d1118fa28d50a0e25..90c407ac656cfcde4109370b22fc6960e612ffb3 100644 (file)
@@ -1532,6 +1532,9 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond,
   else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Cond)) {
     return getTrylockCallExpr(CE->getSubExpr(), C, Negate);
   }
+  else if (const ExprWithCleanups* EWC = dyn_cast<ExprWithCleanups>(Cond)) {
+    return getTrylockCallExpr(EWC->getSubExpr(), C, Negate);
+  }
   else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Cond)) {
     const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C);
     return getTrylockCallExpr(E, C, Negate);
index 7d0d6430d9bd7c2779094d4b8e1b04f114a5b4ed..cf378c50907aa29346a5287a403c2e8e6950706d 100644 (file)
@@ -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();
+}
+
+}
+
+