r197251 - Objective-C. Do not issue warning when 'readonly'

Fariborz Jahanian fjahanian at apple.com
Fri Dec 13 10:19:59 PST 2013


Author: fjahanian
Date: Fri Dec 13 12:19:59 2013
New Revision: 197251

URL: http://llvm.org/viewvc/llvm-project?rev=197251&view=rev
Log:
Objective-C. Do not issue warning when 'readonly'
property declaration has a memory management
attribute (retain, copy, etc.). Sich properties
are usually overridden to become 'readwrite'
via a class extension (which require the memory
management attribute specified). In the absence of class
extension override, memory management attribute is
needed to produce correct Code Gen. for the
property getter in any case and this warning becomes
confusing to user. // rdar://15641300

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/overriding-property-in-class-extension.m
    cfe/trunk/test/SemaObjC/property-12.m
    cfe/trunk/test/SemaObjC/property-in-class-extension-1.m
    cfe/trunk/test/SemaObjC/tentative-property-decl.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Dec 13 12:19:59 2013
@@ -365,7 +365,6 @@ def UnusedVariable : DiagGroup<"unused-v
 def UnusedPropertyIvar :  DiagGroup<"unused-property-ivar">;
 def UsedButMarkedUnused : DiagGroup<"used-but-marked-unused">;
 def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
-def ReadOnlySetterAttrs : DiagGroup<"readonly-setter-attrs">;
 def Reorder : DiagGroup<"reorder">;
 def UndeclaredSelector : DiagGroup<"undeclared-selector">;
 def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 13 12:19:59 2013
@@ -822,9 +822,6 @@ def error_dynamic_property_ivar_decl : E
 def error_duplicate_ivar_use : Error<
   "synthesized properties %0 and %1 both claim instance variable %2">;
 def error_property_implemented : Error<"property %0 is already implemented">;
-def warn_objc_property_attr_mutually_exclusive : Warning<
-  "property attributes '%0' and '%1' are mutually exclusive">,
-  InGroup<ReadOnlySetterAttrs>, DefaultIgnore;
 def warn_objc_missing_super_call : Warning<
   "method possibly missing a [super %0] call">,
   InGroup<ObjCMissingSuperCalls>;

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Dec 13 12:19:59 2013
@@ -321,21 +321,6 @@ static unsigned getOwnershipRule(unsigne
                  ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
 }
 
-static const char *NameOfOwnershipAttribute(unsigned attr) {
-  if (attr & ObjCPropertyDecl::OBJC_PR_assign)
-    return "assign";
-  if (attr & ObjCPropertyDecl::OBJC_PR_retain )
-    return "retain";
-  if (attr & ObjCPropertyDecl::OBJC_PR_copy)
-    return "copy";
-  if (attr & ObjCPropertyDecl::OBJC_PR_weak)
-    return "weak";
-  if (attr & ObjCPropertyDecl::OBJC_PR_strong)
-    return "strong";
-  assert(attr & ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
-  return "unsafe_unretained";
-}
-
 ObjCPropertyDecl *
 Sema::HandlePropertyInClassExtension(Scope *S,
                                      SourceLocation AtLoc,
@@ -2057,21 +2042,13 @@ void Sema::CheckObjCPropertyAttributes(D
   QualType PropertyTy = PropertyDecl->getType();
   unsigned PropertyOwnership = getOwnershipRule(Attributes);
 
-  if (Attributes & ObjCDeclSpec::DQ_PR_readonly) {
-    if (getLangOpts().ObjCAutoRefCount &&
-        PropertyTy->isObjCRetainableType() &&
-        !PropertyOwnership) {
-      // 'readonly' property with no obvious lifetime.
-      // its life time will be determined by its backing ivar.
-      return;
-    }
-    else if (PropertyOwnership) {
-      if (!getSourceManager().isInSystemHeader(Loc))
-        Diag(Loc, diag::warn_objc_property_attr_mutually_exclusive)
-          << "readonly" << NameOfOwnershipAttribute(Attributes);
-      return;
-    }
-  }
+  // 'readonly' property with no obvious lifetime.
+  // its life time will be determined by its backing ivar.
+  if (getLangOpts().ObjCAutoRefCount &&
+      Attributes & ObjCDeclSpec::DQ_PR_readonly &&
+      PropertyTy->isObjCRetainableType() &&
+      !PropertyOwnership)
+    return;
 
   // Check for copy or retain on non-object types.
   if ((Attributes & (ObjCDeclSpec::DQ_PR_weak | ObjCDeclSpec::DQ_PR_copy |

Modified: cfe/trunk/test/SemaObjC/overriding-property-in-class-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/overriding-property-in-class-extension.m?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/overriding-property-in-class-extension.m (original)
+++ cfe/trunk/test/SemaObjC/overriding-property-in-class-extension.m Fri Dec 13 12:19:59 2013
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1  -fsyntax-only -verify -Weverything %s
+// expected-no-diagnostics
 // rdar://12103434
 
 @class NSString;
@@ -7,7 +8,7 @@
 
 @interface MyClass  : NSObject
 
- at property (nonatomic, copy, readonly) NSString* name; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+ at property (nonatomic, copy, readonly) NSString* name;
 
 @end
 

Modified: cfe/trunk/test/SemaObjC/property-12.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-12.m?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-12.m (original)
+++ cfe/trunk/test/SemaObjC/property-12.m Fri Dec 13 12:19:59 2013
@@ -1,15 +1,15 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -Wreadonly-setter-attrs -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 
 @protocol P0
- at property(readonly,assign) id X; // expected-warning {{property attributes 'readonly' and 'assign' are mutually exclusive}}
+ at property(readonly,assign) id X;
 @end
 
 @protocol P1
- at property(readonly,retain) id X; // expected-warning {{property attributes 'readonly' and 'retain' are mutually exclusive}}
+ at property(readonly,retain) id X;
 @end
 
 @protocol P2
- at property(readonly,copy) id X; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+ at property(readonly,copy) id X;
 @end
 
 @protocol P3

Modified: cfe/trunk/test/SemaObjC/property-in-class-extension-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-in-class-extension-1.m?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-in-class-extension-1.m (original)
+++ cfe/trunk/test/SemaObjC/property-in-class-extension-1.m Fri Dec 13 12:19:59 2013
@@ -8,20 +8,19 @@
 
 @property (nonatomic, readonly) NSString* addingMemoryModel;
 
- at property (nonatomic, copy, readonly) NSString* matchingMemoryModel; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+ at property (nonatomic, copy, readonly) NSString* matchingMemoryModel;
 
- at property (nonatomic, retain, readonly) NSString* addingNoNewMemoryModel; // expected-warning {{property attributes 'readonly' and 'retain' are mutually exclusive}}
+ at property (nonatomic, retain, readonly) NSString* addingNoNewMemoryModel;
 
 @property (readonly) NSString* none;
 @property (readonly) NSString* none1;
 
- at property (assign, readonly) NSString* changeMemoryModel; // expected-note {{property declared here}} \
-                                                          // expected-warning {{property attributes 'readonly' and 'assign' are mutually exclusive}}
+ at property (assign, readonly) NSString* changeMemoryModel; // expected-note {{property declared here}}
 
 @property (readonly) __weak id weak_prop;
 @property (readonly) __weak id weak_prop1;
 
- at property (assign, readonly) NSString* assignProperty; // expected-warning {{property attributes 'readonly' and 'assign' are mutually exclusive}}
+ at property (assign, readonly) NSString* assignProperty;
 
 @property (readonly) NSString* readonlyProp;
 

Modified: cfe/trunk/test/SemaObjC/tentative-property-decl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/tentative-property-decl.m?rev=197251&r1=197250&r2=197251&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/tentative-property-decl.m (original)
+++ cfe/trunk/test/SemaObjC/tentative-property-decl.m Fri Dec 13 12:19:59 2013
@@ -1,10 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -Weverything -verify %s
+// expected-no-diagnostics
 // rdar://11656982
-/** Normally, a property cannot be both 'readonly' and having a "write" attribute
+/** A property may not be both 'readonly' and having a memory management attribute
     (copy/retain/etc.). But, property declaration in primary class and protcols
     are tentative as they may be overridden into a 'readwrite' property in class 
-    extensions. Postpone diagnosing such warnings until the class implementation 
-    is seen.
+    extensions. So, do not issue any warning on 'readonly' and memory management
+    attributes in a property.
 */
 
 @interface Super {
@@ -14,8 +15,8 @@
 @class NSString;
 
 @interface MyClass : Super
- at property(nonatomic, copy, readonly) NSString *prop; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
- at property(nonatomic, copy, readonly) id warnProp; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+ at property(nonatomic, copy, readonly) NSString *prop;
+ at property(nonatomic, copy, readonly) id warnProp;
 @end
 
 @interface MyClass ()
@@ -29,8 +30,8 @@
 
 
 @protocol P
- at property(nonatomic, copy, readonly) NSString *prop; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
- at property(nonatomic, copy, readonly) id warnProp; // expected-warning {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+ at property(nonatomic, copy, readonly) NSString *prop;
+ at property(nonatomic, copy, readonly) id warnProp;
 @end
 
 @interface YourClass : Super <P>





More information about the cfe-commits mailing list