]> granicus.if.org Git - clang/commitdiff
Tweak the retain/release checker to not stop tracking retained objects when calling...
authorTed Kremenek <kremenek@apple.com>
Mon, 2 May 2011 21:21:42 +0000 (21:21 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 2 May 2011 21:21:42 +0000 (21:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130726 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CFRefCount.cpp
test/Analysis/retain-release.mm

index 9fd7fc7d4cbe8c7a887c88c8d77e2244d03cb00d..366f6b0665ce1147caadc510a811a453981eb00a 100644 (file)
@@ -930,6 +930,13 @@ RetainSummary* RetainSummaryManager::getSummary(const FunctionDecl* FD) {
       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.
index 47d615f1889638447bd96a5af206c1a2e7721e1c..0faeb1a2a30059fa4be354f9ba07b35650919959 100644 (file)
@@ -275,10 +275,32 @@ class SmartPointer {
 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);
+}
+
+