r331409 - [ObjC] The absence of ownership qualifiers on an ambiguous property leads

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 15:40:19 PDT 2018


Author: arphaman
Date: Wed May  2 15:40:19 2018
New Revision: 331409

URL: http://llvm.org/viewvc/llvm-project?rev=331409&view=rev
Log:
[ObjC] The absence of ownership qualifiers on an ambiguous property leads
to synthesis of a valid property even when the selected protocol property
has ownership qualifiers

rdar://39024725

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=331409&r1=331408&r2=331409&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed May  2 15:40:19 2018
@@ -897,14 +897,24 @@ SelectPropertyForSynthesisFromProtocols(
                                                  : HasUnexpectedAttribute;
         Mismatches.push_back({Prop, Kind, AttributeName});
       };
-      if (isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
+      // The ownership might be incompatible unless the property has no explicit
+      // ownership.
+      bool HasOwnership = (Attr & (ObjCPropertyDecl::OBJC_PR_retain |
+                                   ObjCPropertyDecl::OBJC_PR_strong |
+                                   ObjCPropertyDecl::OBJC_PR_copy |
+                                   ObjCPropertyDecl::OBJC_PR_assign |
+                                   ObjCPropertyDecl::OBJC_PR_unsafe_unretained |
+                                   ObjCPropertyDecl::OBJC_PR_weak)) != 0;
+      if (HasOwnership &&
+          isIncompatiblePropertyAttribute(OriginalAttributes, Attr,
                                           ObjCPropertyDecl::OBJC_PR_copy)) {
         Diag(OriginalAttributes & ObjCPropertyDecl::OBJC_PR_copy, "copy");
         continue;
       }
-      if (areIncompatiblePropertyAttributes(
-              OriginalAttributes, Attr, ObjCPropertyDecl::OBJC_PR_retain |
-                                            ObjCPropertyDecl::OBJC_PR_strong)) {
+      if (HasOwnership && areIncompatiblePropertyAttributes(
+                              OriginalAttributes, Attr,
+                              ObjCPropertyDecl::OBJC_PR_retain |
+                                  ObjCPropertyDecl::OBJC_PR_strong)) {
         Diag(OriginalAttributes & (ObjCPropertyDecl::OBJC_PR_retain |
                                    ObjCPropertyDecl::OBJC_PR_strong),
              "retain (or strong)");

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=331409&r1=331408&r2=331409&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m Wed May  2 15:40:19 2018
@@ -252,3 +252,38 @@ __attribute__((objc_root_class))
 @synthesize prop = _prop;
 
 @end
+
+// rdar://39024725
+// Allow strong readwrite property and a readonly one.
+ at protocol StrongCollision
+
+ at property(strong) NSObject *p;
+ at property(copy) NSObject *p2;
+
+// expected-error at +1 {{property with attribute 'retain (or strong)' was selected for synthesis}}
+ at property(strong, readwrite) NSObject *collision;
+
+ at end
+
+ at protocol ReadonlyCollision
+
+ at property(readonly) NSObject *p;
+ at property(readonly) NSObject *p2;
+
+// expected-note at +1 {{it could also be property without attribute 'retain (or strong)' declared here}}
+ at property(readonly, weak) NSObject *collision;
+
+ at end
+
+ at interface StrongReadonlyCollision : NSObject <StrongCollision, ReadonlyCollision>
+ at end
+
+ at implementation StrongReadonlyCollision
+
+// no error
+ at synthesize p = _p;
+ at synthesize p2 = _p2;
+
+ at synthesize collision = _collision; // expected-note {{property synthesized here}}
+
+ at end




More information about the cfe-commits mailing list