]> granicus.if.org Git - clang/commitdiff
retain/release checker: Improve diagnostics to indicate that CF objects are not autom...
authorTed Kremenek <kremenek@apple.com>
Wed, 28 Jan 2009 06:25:48 +0000 (06:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 28 Jan 2009 06:25:48 +0000 (06:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63187 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/CFDateGC.m

index bd5e3b4d53728405972203fc37f64cc62cb8dae4..625eda4fb19642972efdd5f1c929bbb902dfe208 100644 (file)
@@ -2356,8 +2356,15 @@ PathDiagnosticPiece* CFRefReport::VisitNode(const ExplodedNode<GRState>* N,
       os << " returns an Objective-C object with a ";
     }
     
-    if (CurrV.isOwned())
-        os << "+1 retain count (owning reference).";
+    if (CurrV.isOwned()) {
+      os << "+1 retain count (owning reference).";
+      
+      if (static_cast<CFRefBug&>(getBugType()).getTF().isGCEnabled()) {
+        assert(CurrV.getObjKind() == RetEffect::CF);
+        os << "  "
+          "Core Foundation objects are not automatically garbage collected.";
+      }
+    }
     else {
       assert (CurrV.isNotOwned());
       os << "+0 retain count (non-owning reference).";
index 5ed8ae960937dc1851aca0e89c788f7a2470c5a5..c405fe24e590bbd44075d3c752d8f0dce60ee335 100644 (file)
@@ -26,6 +26,7 @@ typedef signed char BOOL;
 static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef cf) {}
 @protocol NSObject  - (BOOL)isEqual:(id)object;
 - (oneway void)release;
+- (id)retain;
 @end
 @class NSArray;
 
@@ -46,7 +47,7 @@ CFAbsoluteTime f1_use_after_release() {
 
 // The following two test cases verifies that CFMakeCollectable is a no-op
 // in non-GC mode and a "release" in GC mode.
-CFAbsoluteTime f2_leak() {
+CFAbsoluteTime f2_use_after_release() {
   CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
   CFDateRef date = CFDateCreate(0, t);
   CFRetain(date);
@@ -68,6 +69,11 @@ CFAbsoluteTime f2_noleak() {
   return t;
 }
 
+void f3_leak_with_gc() {
+  CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
+  [[(id) date retain] release]; // expected-warning{{leak}}
+}
+
 // The following test case verifies that we "stop tracking" a retained object
 // when it is passed as an argument to an implicitly defined function.
 CFAbsoluteTime f4() {