r199820 - ObjectiveC. When issuing property implementation is

Fariborz Jahanian fjahanian at apple.com
Wed Jan 22 11:02:20 PST 2014


Author: fjahanian
Date: Wed Jan 22 13:02:20 2014
New Revision: 199820

URL: http://llvm.org/viewvc/llvm-project?rev=199820&view=rev
Log:
ObjectiveC. When issuing property implementation is
not using backing ivar warning, ignore when
property is not being synthesized (user declared its
implementation @dynamic). // rdar://1583425

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=199820&r1=199819&r2=199820&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Jan 22 13:02:20 2014
@@ -1405,6 +1405,10 @@ public:
 
   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
                                       ObjCProtocolDecl *rProto) const;
+  
+  ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl(
+                                                  const ObjCPropertyDecl *PD,
+                                                  const Decl *Container) const;
 
   /// \brief Return the size of type \p T for Objective-C encoding purpose,
   /// in characters.

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=199820&r1=199819&r2=199820&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jan 22 13:02:20 2014
@@ -4960,6 +4960,34 @@ bool ASTContext::getObjCEncodingForMetho
   return false;
 }
 
+ObjCPropertyImplDecl *
+ASTContext::getObjCPropertyImplDeclForPropertyDecl(
+                                      const ObjCPropertyDecl *PD,
+                                      const Decl *Container) const {
+  if (!Container)
+    return 0;
+  if (const ObjCCategoryImplDecl *CID =
+      dyn_cast<ObjCCategoryImplDecl>(Container)) {
+    for (ObjCCategoryImplDecl::propimpl_iterator
+         i = CID->propimpl_begin(), e = CID->propimpl_end();
+         i != e; ++i) {
+      ObjCPropertyImplDecl *PID = *i;
+        if (PID->getPropertyDecl() == PD)
+          return PID;
+      }
+    } else {
+      const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container);
+      for (ObjCCategoryImplDecl::propimpl_iterator
+           i = OID->propimpl_begin(), e = OID->propimpl_end();
+           i != e; ++i) {
+        ObjCPropertyImplDecl *PID = *i;
+        if (PID->getPropertyDecl() == PD)
+          return PID;
+      }
+    }
+  return 0;
+}
+
 /// getObjCEncodingForPropertyDecl - Return the encoded type for this
 /// property declaration. If non-NULL, Container must be either an
 /// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be
@@ -4992,37 +5020,12 @@ void ASTContext::getObjCEncodingForPrope
   bool Dynamic = false;
   ObjCPropertyImplDecl *SynthesizePID = 0;
 
-  // FIXME: Duplicated code due to poor abstraction.
-  if (Container) {
-    if (const ObjCCategoryImplDecl *CID =
-        dyn_cast<ObjCCategoryImplDecl>(Container)) {
-      for (ObjCCategoryImplDecl::propimpl_iterator
-             i = CID->propimpl_begin(), e = CID->propimpl_end();
-           i != e; ++i) {
-        ObjCPropertyImplDecl *PID = *i;
-        if (PID->getPropertyDecl() == PD) {
-          if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
-            Dynamic = true;
-          } else {
-            SynthesizePID = PID;
-          }
-        }
-      }
-    } else {
-      const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container);
-      for (ObjCCategoryImplDecl::propimpl_iterator
-             i = OID->propimpl_begin(), e = OID->propimpl_end();
-           i != e; ++i) {
-        ObjCPropertyImplDecl *PID = *i;
-        if (PID->getPropertyDecl() == PD) {
-          if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
-            Dynamic = true;
-          } else {
-            SynthesizePID = PID;
-          }
-        }
-      }
-    }
+  if (ObjCPropertyImplDecl *PropertyImpDecl =
+      getObjCPropertyImplDeclForPropertyDecl(PD, Container)) {
+    if (PropertyImpDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+      Dynamic = true;
+    else
+      SynthesizePID = PropertyImpDecl;
   }
 
   // FIXME: This is not very efficient.

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=199820&r1=199819&r2=199820&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Jan 22 13:02:20 2014
@@ -3514,6 +3514,13 @@ void Sema::DiagnoseUnusedBackingIvarInAc
     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());

Modified: cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m?rev=199820&r1=199819&r2=199820&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m (original)
+++ cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m Wed Jan 22 13:02:20 2014
@@ -147,3 +147,26 @@ typedef char BOOL;
   return [o Meth];
 }
 @end
+
+// rdar://15873425
+ at protocol MyProtocol
+ at property (nonatomic, readonly) int myProperty;
+ at end
+
+ at interface MyFirstClass : NSObject <MyProtocol>
+ at end
+
+ at interface MySecondClass : NSObject <MyProtocol>
+ at end
+
+ at implementation MyFirstClass
+ at synthesize myProperty;
+ at end
+
+ at implementation MySecondClass
+ at dynamic myProperty;
+-(int)myProperty  // should not warn; property is dynamic
+{
+    return 0;
+}
+ at end





More information about the cfe-commits mailing list