From 10a0316219908628d2ce656963b14ee98bd7ce74 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 27 Jan 2014 22:27:43 +0000 Subject: [PATCH] ObjectiveC. Fixes a bug in recognition of an ivar backing a property resulting in bogus warning. // rdar://15890251 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200254 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 17 +++++++------- test/SemaObjC/unused-backing-ivar-warning.m | 25 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 7d023e1d40..c91ce37711 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -3449,8 +3449,14 @@ Sema::GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, if (!Method || !Method->isPropertyAccessor()) return 0; if ((PDecl = Method->findPropertyDecl())) - return PDecl->getPropertyIvarDecl(); - + if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl()) { + // property backing ivar must belong to property's class + // or be a private ivar in class's implementation. + // FIXME. fix the const-ness issue. + IV = const_cast(IDecl)->lookupInstanceVariable( + IV->getIdentifier()); + return IV; + } return 0; } @@ -3509,13 +3515,6 @@ void Sema::DiagnoseUnusedBackingIvarInAccessor(Scope *S, const ObjCIvarDecl *IV = GetIvarBackingPropertyAccessor(CurMethod, PDecl); if (!IV) continue; - // Property declared as @dynamic must be ignored. - if (ObjCPropertyImplDecl *PropertyImpDecl = - Context.getObjCPropertyImplDeclForPropertyDecl(PDecl, ImplD)) - if (PropertyImpDecl->getPropertyImplementation() == - ObjCPropertyImplDecl::Dynamic) - continue; - UnusedBackingIvarChecker Checker(*this, CurMethod, IV); Checker.TraverseStmt(CurMethod->getBody()); diff --git a/test/SemaObjC/unused-backing-ivar-warning.m b/test/SemaObjC/unused-backing-ivar-warning.m index 59fbc85d60..390d554e14 100644 --- a/test/SemaObjC/unused-backing-ivar-warning.m +++ b/test/SemaObjC/unused-backing-ivar-warning.m @@ -170,3 +170,28 @@ typedef char BOOL; return 0; } @end + +// rdar://15890251 +@class NSURL; + +@protocol MCCIDURLProtocolDataProvider +@required +@property(strong, atomic, readonly) NSURL *cidURL; +@end + +@interface UnrelatedClass : NSObject +@end + +@implementation UnrelatedClass +@synthesize cidURL = _cidURL; +@end + +@interface MUIWebAttachmentController : NSObject +@end + + +@implementation MUIWebAttachmentController +- (NSURL *)cidURL { + return 0; +} +@end -- 2.40.0