]> granicus.if.org Git - clang/commitdiff
ObjectiveC. Fixes a bug in recognition of an ivar
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 27 Jan 2014 22:27:43 +0000 (22:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 27 Jan 2014 22:27:43 +0000 (22:27 +0000)
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
test/SemaObjC/unused-backing-ivar-warning.m

index 7d023e1d403e17108998045089b5f2d2138dcfb8..c91ce37711be18ccce6962ed8473f0d319429af9 100644 (file)
@@ -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<ObjCInterfaceDecl *>(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());
index 59fbc85d609a91e25e4dd543dcc5bf1c4520fd62..390d554e143ceb878acb0809236bfc89045f4363 100644 (file)
@@ -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 <MCCIDURLProtocolDataProvider>
+@end
+
+@implementation UnrelatedClass
+@synthesize cidURL = _cidURL;
+@end
+
+@interface MUIWebAttachmentController : NSObject <MCCIDURLProtocolDataProvider>
+@end
+
+
+@implementation MUIWebAttachmentController
+- (NSURL *)cidURL {
+    return 0;
+}
+@end