]> granicus.if.org Git - clang/commitdiff
Thread safety analysis: minor bugfix to smart pointer handling, and expanded
authorDeLesley Hutchins <delesley@google.com>
Wed, 6 Nov 2013 18:40:01 +0000 (18:40 +0000)
committerDeLesley Hutchins <delesley@google.com>
Wed, 6 Nov 2013 18:40:01 +0000 (18:40 +0000)
test case.

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

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

index 607526db3e59c354b519731d28aa1e5289074832..df163aaf6d63b19a44e722a0850b16cd862472da 100644 (file)
@@ -2137,14 +2137,15 @@ void BuildLockset::VisitCallExpr(CallExpr *Exp) {
       case OO_Star:
       case OO_Arrow: {
         if (Analyzer->Handler.issueBetaWarnings()) {
-          const Expr *Target = OE->getArg(0);
-          checkPtAccess(Target, AK_Read);
+          const Expr *Obj = OE->getArg(0);
+          checkAccess(Obj, AK_Read);
+          checkPtAccess(Obj, AK_Read);
         }
         break;
       }
       default: {
-        const Expr *Source = OE->getArg(0);
-        checkAccess(Source, AK_Read);
+        const Expr *Obj = OE->getArg(0);
+        checkAccess(Obj, AK_Read);
         break;
       }
     }
index 8ea411325fb4d8bf05c965bd1ab7596ccf102b58..fc99456fdf1a30b0fa8b63e8c7346c73a3787347 100644 (file)
@@ -4213,14 +4213,44 @@ class PtGuardedBySanityTest {
 
 
 class SmartPtr_PtGuardedBy_Test {
+  Mutex mu1;
   Mutex mu2;
-  SmartPtr<int>  sp PT_GUARDED_BY(mu2);
-  SmartPtr<Cell> sq PT_GUARDED_BY(mu2);
+  SmartPtr<int>  sp GUARDED_BY(mu1) PT_GUARDED_BY(mu2);
+  SmartPtr<Cell> sq GUARDED_BY(mu1) PT_GUARDED_BY(mu2);
 
-  void test() {
-    sp.get();   // OK -- no GUARDED_BY
-    *sp = 0;    // expected-warning {{reading the value pointed to by 'sp' requires locking 'mu2'}}
-    sq->a = 0;  // expected-warning {{reading the value pointed to by 'sq' requires locking 'mu2'}}
+  void test1() {
+    mu1.ReaderLock();
+    mu2.Lock();
+
+    sp.get();
+    if (*sp == 0) doSomething();
+    *sp = 0;
+    sq->a = 0;
+
+    mu2.Unlock();
+    mu1.Unlock();
+  }
+
+  void test2() {
+    mu2.Lock();
+
+    sp.get();                     // expected-warning {{reading variable 'sp' requires locking 'mu1'}}
+    if (*sp == 0) doSomething();  // expected-warning {{reading variable 'sp' requires locking 'mu1'}}
+    *sp = 0;                      // expected-warning {{reading variable 'sp' requires locking 'mu1'}}
+    sq->a = 0;                    // expected-warning {{reading variable 'sq' requires locking 'mu1'}}
+
+    mu2.Unlock();
+  }
+
+  void test3() {
+    mu1.Lock();
+
+    sp.get();
+    if (*sp == 0) doSomething();  // expected-warning {{reading the value pointed to by 'sp' requires locking 'mu2'}}
+    *sp = 0;                      // expected-warning {{reading the value pointed to by 'sp' requires locking 'mu2'}}
+    sq->a = 0;                    // expected-warning {{reading the value pointed to by 'sq' requires locking 'mu2'}}
+
+    mu1.Unlock();
   }
 };