]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same...
authorTed Kremenek <kremenek@apple.com>
Tue, 12 May 2009 04:53:03 +0000 (04:53 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 12 May 2009 04:53:03 +0000 (04:53 +0000)
This was accomplished by having 'isTypeRef' recursively walk the typedef stack.

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

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

index bc140077dc768907880b322e1350ba839aa58b23..5120d4f0fc508ddb08828048d0ca65bbeab50b5b 100644 (file)
@@ -225,9 +225,17 @@ static bool hasSuffix(const char* s, const char* suffix) {
 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)
index f4c2d25054142b942d1f38c892402a1a14af886c..5f2a1c8f8581b2fc28b1fd532deb08ebc67111d6 100644 (file)
@@ -528,6 +528,27 @@ void rdar_6866843() {
  [pool drain];
 }
 
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same treatment as CF objects
+//===----------------------------------------------------------------------===//
+
+typedef CFTypeRef OtherRef;
+
+@interface RDar6877235 : NSObject {}
+- (CFTypeRef)_copyCFTypeRef;
+- (OtherRef)_copyOtherRef;
+@end
+
+@implementation RDar6877235
+- (CFTypeRef)_copyCFTypeRef {
+  return [[NSString alloc] init]; // no-warning
+}
+- (OtherRef)_copyOtherRef {
+  return [[NSString alloc] init]; // no-warning
+}
+@end
+
 //===----------------------------------------------------------------------===//
 // Tests of ownership attributes.
 //===----------------------------------------------------------------------===//