[cfe-commits] r130726 - in /cfe/trunk: lib/StaticAnalyzer/Core/CFRefCount.cpp test/Analysis/retain-release.mm

Ted Kremenek kremenek at apple.com
Mon May 2 14:21:42 PDT 2011


Author: kremenek
Date: Mon May  2 16:21:42 2011
New Revision: 130726

URL: http://llvm.org/viewvc/llvm-project?rev=130726&view=rev
Log:
Tweak the retain/release checker to not stop tracking retained objects when calling C++ methods.  This is a temporary solution to prune false positives until we have a general story using annotations.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
    cfe/trunk/test/Analysis/retain-release.mm

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=130726&r1=130725&r2=130726&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Mon May  2 16:21:42 2011
@@ -930,6 +930,13 @@
       S = getPersistentStopSummary();
       break;
     }
+    // For C++ methods, generate an implicit "stop" summary as well.  We
+    // can relax this once we have a clear policy for C++ methods and
+    // ownership attributes.
+    if (isa<CXXMethodDecl>(FD)) {
+      S = getPersistentStopSummary();
+      break;
+    }
 
     // [PR 3337] Use 'getAs<FunctionType>' to strip away any typedefs on the
     // function's type.

Modified: cfe/trunk/test/Analysis/retain-release.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.mm?rev=130726&r1=130725&r2=130726&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.mm (original)
+++ cfe/trunk/test/Analysis/retain-release.mm Mon May  2 16:21:42 2011
@@ -275,10 +275,32 @@
 public:
   SmartPointer(id x) : x(x) {}
   ~SmartPointer() { [x release]; }
+
+  void adopt(id x);
+  void noAdopt(id x);
 };
 
+void test_positive() {
+  id x = [[NSObject alloc] init]; // expected-warning {{leak}}
+}
+
 void test_smartpointer_1() {
   id x = [[NSObject alloc] init];  // no-warning
   SmartPointer foo(x);
 }
 
+void test_smartpointer_2() {
+  id x = [[NSObject alloc] init];  // no-warning
+  SmartPointer foo(0);
+  foo.adopt(x);
+}
+
+// FIXME: Eventually we want annotations to say whether or not
+// a C++ method claims ownership of an Objective-C object.
+void test_smartpointer_3() {
+  id x = [[NSObject alloc] init];  // no-warning
+  SmartPointer foo(0);
+  foo.noAdopt(x);
+}
+
+





More information about the cfe-commits mailing list