]> granicus.if.org Git - clang/commitdiff
retain/release checker: Don't call isTrackedObject() with the canonical type.
authorTed Kremenek <kremenek@apple.com>
Thu, 23 Apr 2009 21:25:57 +0000 (21:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 23 Apr 2009 21:25:57 +0000 (21:25 +0000)
This was preventing the checker from tracking return objects referenced by 'id'.

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

lib/Analysis/CFRefCount.cpp
test/Analysis/NSString.m
test/Analysis/retain-release.m

index 98221fe32bdc9f77d1ad16e378d0daa9a7f9fe45..575a47b77660431da7dbcbebb96d2e30775c9230 100644 (file)
@@ -703,7 +703,7 @@ public:
   
   RetainSummary* getSummary(FunctionDecl* FD);  
   RetainSummary* getMethodSummary(ObjCMessageExpr* ME, ObjCInterfaceDecl* ID);
-  RetainSummary* getClassMethodSummary(ObjCMessageExpr *ME, Selector S);
+  RetainSummary* getClassMethodSummary(ObjCMessageExpr *ME);
   
   bool isGCEnabled() const { return GCEnabled; }
 };
@@ -1071,7 +1071,7 @@ RetainSummaryManager::getMethodSummary(ObjCMessageExpr* ME,
     return getInitMethodSummary(ME);
   
   // Look for methods that return an owned object.
-  if (!isTrackedObjectType(Ctx.getCanonicalType(ME->getType())))
+  if (!isTrackedObjectType(ME->getType()))
     return 0;
 
   // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
@@ -1089,13 +1089,13 @@ RetainSummaryManager::getMethodSummary(ObjCMessageExpr* ME,
 }
 
 RetainSummary*
-RetainSummaryManager::getClassMethodSummary(ObjCMessageExpr* ME,
-                                            Selector S) {
+RetainSummaryManager::getClassMethodSummary(ObjCMessageExpr* ME) {
   
   // FIXME: Eventually we should properly do class method summaries, but
   // it requires us being able to walk the type hierarchy.  Unfortunately,
   // we cannot do this with just an IdentifierInfo* for the class name.  
   IdentifierInfo* ClsName = ME->getClassName();
+  Selector S = ME->getSelector();
   
   // Look up a summary in our cache of Selectors -> Summaries.
   ObjCMethodSummariesTy::iterator I = ObjCClassMethodSummaries.find(ClsName, S);
@@ -1104,15 +1104,13 @@ RetainSummaryManager::getClassMethodSummary(ObjCMessageExpr* ME,
     return I->second;
   
   // Look for methods that return an owned object.
-  if (!isTrackedObjectType(Ctx.getCanonicalType(ME->getType())))
+  if (!isTrackedObjectType(ME->getType()))
     return 0;
   
   // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
   //  by class methods.
   // Look for methods that return an owned object.
-  if (!isTrackedObjectType(Ctx.getCanonicalType(ME->getType())))
-    return 0;  
-  
+
   const char* s = S.getIdentifierInfoForSlot(0)->getName();
   RetEffect E = followsFundamentalRule(s)
     ? (isGCEnabled() ? RetEffect::MakeNotOwned(RetEffect::ObjC)
@@ -2014,7 +2012,7 @@ void CFRefCount::EvalObjCMessageExpr(ExplodedNodeSet<GRState>& Dst,
     }
   }
   else
-    Summ = Summaries.getClassMethodSummary(ME, ME->getSelector());
+    Summ = Summaries.getClassMethodSummary(ME);
 
   EvalSummary(Dst, Eng, Builder, ME, ME->getReceiver(), Summ,
               ME->arg_begin(), ME->arg_end(), Pred);
index a486e0e07160591393ff9388010491543cd16c44..a95e8868c3c9e0e0c621b943933b9a685ad4ec00 100644 (file)
@@ -248,6 +248,6 @@ void test_objc_atomicCompareAndSwap() {
 void test_stringWithFormat() {  
   NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain];
   [string release];
-  [string release];
+  [string release]; // expected-warning{{Incorrect decrement of the reference count}}
 }
 
index 5a0471ae88e2df0bc231e8f2504681e4933db908..012e340f563e80c3819eef968dfb50ff6575a7bc 100644 (file)
@@ -335,7 +335,7 @@ static void rdar_6659160(char *inkind, char *inname)
     return;
 
   [kind release];
-  [name release];
+  [name release]; // expected-warning{{Incorrect decrement of the reference count}}
 }
 
 // PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming