]> granicus.if.org Git - clang/commitdiff
Further cleanups to isTrackedObjectType().
authorTed Kremenek <kremenek@apple.com>
Thu, 23 Apr 2009 22:11:07 +0000 (22:11 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 23 Apr 2009 22:11:07 +0000 (22:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69929 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 575a47b77660431da7dbcbebb96d2e30775c9230..052a610db1b4682bbfce8a930b9fe7a61f74a681 100644 (file)
@@ -784,18 +784,22 @@ RetainSummaryManager::getPersistentSummary(ArgEffects* AE, RetEffect RetEff,
 // Predicates.
 //===----------------------------------------------------------------------===//
 
-bool RetainSummaryManager::isTrackedObjectType(QualType T) {
-  if (!Ctx.isObjCObjectPointerType(T))
+bool RetainSummaryManager::isTrackedObjectType(QualType Ty) {
+  if (!Ctx.isObjCObjectPointerType(Ty))
     return false;
 
-  // Does it subclass NSObject?
-  ObjCInterfaceType* OT = dyn_cast<ObjCInterfaceType>(T.getTypePtr());
+  // We assume that id<..>, id, and "Class" all represent tracked objects.
+  const PointerType *PT = Ty->getAsPointerType();
+  if (PT == 0)
+    return true;
+    
+  const ObjCInterfaceType *OT = PT->getPointeeType()->getAsObjCInterfaceType();
 
   // We assume that id<..>, id, and "Class" all represent tracked objects.
   if (!OT)
     return true;
-
-  // Does the object type subclass NSObject?
+    
+  // Does the interface subclass NSObject?
   // FIXME: We can memoize here if this gets too expensive.  
   IdentifierInfo* NSObjectII = &Ctx.Idents.get("NSObject");
   ObjCInterfaceDecl* ID = OT->getDecl();  
index a95e8868c3c9e0e0c621b943933b9a685ad4ec00..3f2b09189e9d93d72afbfa61ef11e4dad431b04b 100644 (file)
@@ -251,3 +251,12 @@ void test_stringWithFormat() {
   [string release]; // expected-warning{{Incorrect decrement of the reference count}}
 }
 
+// Test isTrackedObjectType()
+typedef NSString* WonkyTypedef;
+@interface TestIsTracked
++ (WonkyTypedef)newString;
+@end
+
+void test_isTrackedObjectType(void) {
+  NSString *str = [TestIsTracked newString]; // expected-warning{{Potential leak}}
+}