r255943 - ObjC properties: consider ownership of properties from protocols when synthesizing.

Douglas Gregor via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 17 16:52:32 PST 2015


Author: dgregor
Date: Thu Dec 17 18:52:31 2015
New Revision: 255943

URL: http://llvm.org/viewvc/llvm-project?rev=255943&view=rev
Log:
ObjC properties: consider ownership of properties from protocols when synthesizing.

When determining whether ownership was explicitly written for a
property when it is being synthesized, also consider that the original
property might have come from a protocol. Fixes rdar://problem/23931441.

Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=255943&r1=255942&r2=255943&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Dec 17 18:52:31 2015
@@ -868,6 +868,13 @@ static bool hasWrittenStorageAttribute(O
       return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
   }
 
+  // Look through all of the protocols.
+  for (const auto *Proto : OrigClass->all_referenced_protocols()) {
+    if (ObjCPropertyDecl *OrigProp =
+          Proto->FindPropertyDeclaration(Prop->getIdentifier()))
+      return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask;
+  }
+
   return false;
 }
 

Modified: cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m?rev=255943&r1=255942&r2=255943&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m Thu Dec 17 18:52:31 2015
@@ -105,3 +105,19 @@
 @property(nonatomic, weak, nonnull, readonly) id ROdelegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}}
 @end
 
+// rdar://problem/23931441
+ at protocol P
+ at property(readonly, retain) id prop;
+ at end
+
+__attribute__((objc_root_class))
+ at interface I2<P>
+ at end
+
+ at interface I2()
+ at property (readwrite) id prop;
+ at end
+
+ at implementation I2
+ at synthesize prop;
+ at end




More information about the cfe-commits mailing list