From: Ted Kremenek Date: Wed, 28 Oct 2009 22:18:22 +0000 (+0000) Subject: Unused ivars checker: also check methods in categories that are defined in the same... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8ec699167a7c3a2872feefd03e0ea2fabb980e0;p=clang Unused ivars checker: also check methods in categories that are defined in the same translation unit. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85442 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CheckObjCUnusedIVars.cpp b/lib/Analysis/CheckObjCUnusedIVars.cpp index 6c942aaafc..2d9b53163f 100644 --- a/lib/Analysis/CheckObjCUnusedIVars.cpp +++ b/lib/Analysis/CheckObjCUnusedIVars.cpp @@ -74,6 +74,14 @@ static void Scan(IvarUsageMap& M, const ObjCContainerDecl* D) { for (ObjCImplementationDecl::propimpl_iterator I = ID->propimpl_begin(), E = ID->propimpl_end(); I!=E; ++I) Scan(M, *I); + + // Scan the associated categories as well. + for (const ObjCCategoryDecl *CD = + ID->getClassInterface()->getCategoryList(); CD ; + CD = CD->getNextClassCategory()) { + if (const ObjCCategoryImplDecl *CID = CD->getImplementation()) + Scan(M, CID); + } } } diff --git a/test/Analysis/unused-ivars.m b/test/Analysis/unused-ivars.m index aacd44e7e6..9e9360da50 100644 --- a/test/Analysis/unused-ivars.m +++ b/test/Analysis/unused-ivars.m @@ -43,3 +43,25 @@ b(); } @end + +//===----------------------------------------------------------------------===// +// Detect that ivar is in use, if used in category +// in the same file as the implementation +//===----------------------------------------------------------------------===// + +@protocol Protocol6260004 +- (id) getId; +@end + +@interface RDar6260004 { +@private + id x; // no-warning +} +@end +@implementation RDar6260004 @end +@implementation RDar6260004 (Protocol6260004) +- (id) getId { + return x; +} +@end +