From 95d181936a19882ee1ca82b65cc40ef8ebf45905 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 12 May 2009 04:53:03 +0000 Subject: [PATCH] Fix 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. llvm-svn: 71538 --- clang/lib/Analysis/CFRefCount.cpp | 14 +++++++++++--- clang/test/Analysis/retain-release.m | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp index bc140077dc76..5120d4f0fc50 100644 --- a/clang/lib/Analysis/CFRefCount.cpp +++ b/clang/lib/Analysis/CFRefCount.cpp @@ -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(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(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) diff --git a/clang/test/Analysis/retain-release.m b/clang/test/Analysis/retain-release.m index f4c2d2505414..5f2a1c8f8581 100644 --- a/clang/test/Analysis/retain-release.m +++ b/clang/test/Analysis/retain-release.m @@ -528,6 +528,27 @@ void rdar_6866843() { [pool drain]; } + +//===----------------------------------------------------------------------===// +// 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. //===----------------------------------------------------------------------===//