[cfe-commits] r71538 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Mon May 11 21:53:08 PDT 2009


Author: kremenek
Date: Mon May 11 23:53:03 2009
New Revision: 71538

URL: http://llvm.org/viewvc/llvm-project?rev=71538&view=rev
Log:
Fix <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same treatment as CF objects

This was accomplished by having	'isTypeRef' recursively walk the typedef stack.

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=71538&r1=71537&r2=71538&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon May 11 23:53:03 2009
@@ -225,9 +225,17 @@
 static bool isRefType(QualType RetTy, const char* prefix,
                       ASTContext* Ctx = 0, const char* name = 0) {
   
-  if (TypedefType* TD = dyn_cast<TypedefType>(RetTy.getTypePtr())) {
-    const char* TDName = TD->getDecl()->getIdentifier()->getName();
-    return hasPrefix(TDName, prefix) && hasSuffix(TDName, "Ref");
+  // Recursively walk the typedef stack, allowing typedefs of reference types.
+  while (1) {
+    if (TypedefType* TD = dyn_cast<TypedefType>(RetTy.getTypePtr())) {
+      const char* TDName = TD->getDecl()->getIdentifier()->getName();
+      if (hasPrefix(TDName, prefix) && hasSuffix(TDName, "Ref"))
+        return true;
+      
+      RetTy = TD->getDecl()->getUnderlyingType();
+      continue;
+    }
+    break;
   }
 
   if (!Ctx || !name)

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=71538&r1=71537&r2=71538&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Mon May 11 23:53:03 2009
@@ -528,6 +528,27 @@
  [pool drain];
 }
 
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same treatment as CF objects
+//===----------------------------------------------------------------------===//
+
+typedef CFTypeRef OtherRef;
+
+ at interface RDar6877235 : NSObject {}
+- (CFTypeRef)_copyCFTypeRef;
+- (OtherRef)_copyOtherRef;
+ at end
+
+ at implementation RDar6877235
+- (CFTypeRef)_copyCFTypeRef {
+  return [[NSString alloc] init]; // no-warning
+}
+- (OtherRef)_copyOtherRef {
+  return [[NSString alloc] init]; // no-warning
+}
+ at end
+
 //===----------------------------------------------------------------------===//
 // Tests of ownership attributes.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list