From 4417498c9f31829c1c2e0b0a99db13420e988746 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 15 Nov 2013 17:48:00 +0000 Subject: [PATCH] ObjectiveC. Fixes a bogus warning of unused backing ivar when property belongs to a super class and currnt class happens to have a method with same name as property. // rdar//15473432 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194830 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 11 ++++++++- test/SemaObjC/unsued-backing-ivar-warning.m | 25 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 86979a1fe8..f44fb32511 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -3510,8 +3510,17 @@ Sema::GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, Method = IDecl->lookupMethod(Method->getSelector(), true); if (!Method || !Method->isPropertyAccessor()) return 0; - if ((PDecl = Method->findPropertyDecl())) + if ((PDecl = Method->findPropertyDecl())) { + if (!PDecl->getDeclContext()) + return 0; + // Make sure property belongs to accessor's class and not to + // one of its super classes. + if (const ObjCInterfaceDecl *CID = + dyn_cast(PDecl->getDeclContext())) + if (CID != IDecl) + return 0; return PDecl->getPropertyIvarDecl(); + } return 0; } diff --git a/test/SemaObjC/unsued-backing-ivar-warning.m b/test/SemaObjC/unsued-backing-ivar-warning.m index 2f55efabcd..c07dea71a7 100644 --- a/test/SemaObjC/unsued-backing-ivar-warning.m +++ b/test/SemaObjC/unsued-backing-ivar-warning.m @@ -49,3 +49,28 @@ okIvar = newT; } @end + +// rdar://15473432 +typedef char BOOL; +@interface CalDAVServerVersion { + BOOL _supportsTimeRangeFilterWithoutEndDate; +} +@property (nonatomic, readonly,nonatomic) BOOL supportsTimeRangeFilterWithoutEndDate; +@end + +@interface CalDAVConcreteServerVersion : CalDAVServerVersion { +} +@end + +@interface CalendarServerVersion : CalDAVConcreteServerVersion +@end + +@implementation CalDAVServerVersion +@synthesize supportsTimeRangeFilterWithoutEndDate=_supportsTimeRangeFilterWithoutEndDate; +@end + +@implementation CalendarServerVersion +-(BOOL)supportsTimeRangeFilterWithoutEndDate { + return 0; +} +@end -- 2.40.0