]> granicus.if.org Git - clang/commitdiff
"Teach" RetainCountChecker about dispatch_set_context, which can indirectly free...
authorTed Kremenek <kremenek@apple.com>
Thu, 22 Mar 2012 06:29:41 +0000 (06:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 22 Mar 2012 06:29:41 +0000 (06:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153244 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/objc-arc.m

index 4f21c2a16b25c5d30d7318145074bccc63b6310e..940228e679539455281043eec7fb952f542e65bd 100644 (file)
@@ -985,6 +985,14 @@ const RetainSummary * RetainSummaryManager::getSummary(const FunctionDecl *FD) {
       // correctly.
       ScratchArgs = AF.add(ScratchArgs, 12, StopTracking);
       S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
+    } else if (FName == "dispatch_set_context") {
+      // <rdar://problem/11059275> - The analyzer currently doesn't have
+      // a good way to reason about the finalizer function for libdispatch.
+      // If we pass a context object that is memory managed, stop tracking it.
+      // FIXME: this hack should possibly go away once we can handle
+      // libdispatch finalizers.
+      ScratchArgs = AF.add(ScratchArgs, 1, StopTracking);
+      S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
     }
 
     // Did we get a summary?
index a5bf05f38a9f27f5faa47530cec242e8caac59ab..e6c6ab546132bb08bfafe615ae16cfc4adf34b65 100644 (file)
@@ -200,4 +200,21 @@ void test_objc_arrays() {
     }
 }
 
+// <rdar://problem/11059275> - dispatch_set_context and ARC.
+__attribute__((cf_returns_retained)) CFTypeRef CFBridgingRetain(id X);
+typedef void* dispatch_object_t;
+void dispatch_set_context(dispatch_object_t object, const void *context);
+
+void rdar11059275(dispatch_object_t object) {
+  NSObject *o = [[NSObject alloc] init];
+  dispatch_set_context(object, CFBridgingRetain(o)); // no-warning  
+}
+void rdar11059275_positive() {
+  NSObject *o = [[NSObject alloc] init]; // expected-warning {{leak}}
+  CFBridgingRetain(o);
+}
+void rdar11059275_negative() {
+  NSObject *o = [[NSObject alloc] init]; // no-warning
+  (void) o;
+}