]> granicus.if.org Git - clang/commitdiff
Tweak the ObjCAtSyncChecker to assume that a mutex is non-nil after checking that...
authorTed Kremenek <kremenek@apple.com>
Thu, 21 Oct 2010 15:38:55 +0000 (15:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 21 Oct 2010 15:38:55 +0000 (15:38 +0000)
nil.  Otherwise we can get false paths where a second @synchronized using the mutex
can have a bogus warning.  Fixes <rdar://problem/8578650>.

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

lib/Checker/ObjCAtSyncChecker.cpp
test/Analysis/misc-ps.m

index dc2e664e0549b9b5678244881506b0e9b596af50..41580955a9a4fade0e366a799c62f1b31f019acf 100644 (file)
@@ -75,13 +75,15 @@ void ObjCAtSyncChecker::PreVisitObjCAtSynchronizedStmt(CheckerContext &C,
                                   Ex);
 
         C.EmitReport(report);
+        return;
       }
     }
-    // From this point forward, we know that the mutex is null.
-    C.addTransition(nullState);
+    // Don't add a transition for 'nullState'.  If the value is
+    // under-constrained to be null or non-null, assume it is non-null
+    // afterwards.
   }
 
   if (notNullState)
     C.addTransition(notNullState);
 }
+
index bb70c90e6a62276f8d36b33ac62ef7ec2446d441..2409be351c7ace7d0a5e875a2b4ec68e199330a6 100644 (file)
@@ -1110,6 +1110,20 @@ void rdar6351970_c() {
   @synchronized(x) {} // expected-warning{{Uninitialized value used as mutex for @synchronized}}
 }
 
+@interface Rdar8578650
+- (id) foo8578650;
+@end
+
+void rdar8578650(id x) {
+  @synchronized (x) {
+    [x foo8578650];
+  }
+  // At this point we should assume that 'x' is not nil, not
+  // the inverse.
+  @synchronized (x) { // no-warning
+  }
+}
+
 // <rdar://problem/6352035> rule request: direct structure member access null pointer dereference
 @interface RDar6352035 {
   int c;