From b1585c8a9976de3b63b578ebcd17f4ee7bd4a420 Mon Sep 17 00:00:00 2001
From: Fariborz Jahanian <fjahanian@apple.com>
Date: Fri, 29 Aug 2014 18:31:16 +0000
Subject: [PATCH] Objective-C. Tweak diagnosing properties that are not
 auto-synthesized. Do not warn when property declared in class's protocol will
 be auto-synthesized by its uper class implementation because super class has
 also declared this property while this class has not. Continue to warn if
 current class has declared the property also (because this declaration will
 not result in a 2nd synthesis). rdar://18152478

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216753 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Basic/DiagnosticSemaKinds.td    |  3 +-
 lib/Sema/SemaObjCProperty.cpp                 | 39 +++++++++----------
 test/Analysis/objc_invalidation.m             |  4 +-
 test/SemaObjC/attr-deprecated.m               |  2 +-
 test/SemaObjC/default-synthesize-1.m          |  2 +-
 test/SemaObjC/default-synthesize.m            | 26 ++++++++++++-
 .../SemaObjC/protocols-suppress-conformance.m | 10 ++---
 test/SemaObjC/super-property-notation.m       |  2 +-
 8 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 8b25adb3377..1cd372b5f6e 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -787,7 +787,8 @@ def warn_no_autosynthesis_property : Warning<
   InGroup<ObjCNoPropertyAutoSynthesis>;
 def warn_autosynthesis_property_in_superclass : Warning<
   "auto property synthesis will not synthesize property "
-  "%0 because it will be implemented by its superclass">,
+  "%0; it will be implemented by its superclass, use @dynamic to "
+  "acknowledge intention">,
   InGroup<ObjCNoPropertyAutoSynthesis>;
 def warn_autosynthesis_property_ivar_match :Warning<
   "autosynthesized property %0 will use %select{|synthesized}1 instance variable "
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 0963c1ee3da..ba698c1b3c3 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -1547,25 +1547,6 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
       if (IMPDecl->getInstanceMethod(Prop->getSetterName()))
         continue;
     }
-    // If property to be implemented in the super class, ignore.
-    if (SuperPropMap[Prop->getIdentifier()]) {
-      ObjCPropertyDecl *PropInSuperClass = SuperPropMap[Prop->getIdentifier()];
-      if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) &&
-          (PropInSuperClass->getPropertyAttributes() &
-           ObjCPropertyDecl::OBJC_PR_readonly) &&
-          !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
-          !IDecl->HasUserDeclaredSetterMethod(Prop)) {
-        Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
-          << Prop->getIdentifier();
-        Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
-      }
-      else {
-        Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
-          << Prop->getIdentifier();
-        Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
-      }
-      continue;
-    }
     if (ObjCPropertyImplDecl *PID =
         IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
       Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
@@ -1587,7 +1568,25 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
       }
       continue;
     }
-
+    // If property to be implemented in the super class, ignore.
+    if (ObjCPropertyDecl *PropInSuperClass =
+          SuperPropMap[Prop->getIdentifier()]) {
+      if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) &&
+          (PropInSuperClass->getPropertyAttributes() &
+           ObjCPropertyDecl::OBJC_PR_readonly) &&
+          !IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
+          !IDecl->HasUserDeclaredSetterMethod(Prop)) {
+        Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
+        << Prop->getIdentifier();
+        Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
+      }
+      else {
+        Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
+        << Prop->getIdentifier();
+        Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
+      }
+      continue;
+    }
     // We use invalid SourceLocations for the synthesized ivars since they
     // aren't really synthesized at a particular location; they just exist.
     // Saying that they are located at the @implementation isn't really going
diff --git a/test/Analysis/objc_invalidation.m b/test/Analysis/objc_invalidation.m
index 9ac98284b4e..0d97b2952de 100644
--- a/test/Analysis/objc_invalidation.m
+++ b/test/Analysis/objc_invalidation.m
@@ -199,7 +199,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
 // synthesized in the parent, let the parent invalidate it.
 
 @protocol IDEBuildable <NSObject>
-@property (readonly, strong) id <Invalidation2> ObjB; // expected-warning {{auto property synthesis will not synthesize property 'ObjB'}}
+@property (readonly, strong) id <Invalidation2> ObjB; // expected-note {{property declared here}}
 @end
 
 @interface Parent : NSObject <IDEBuildable, Invalidation2> {
@@ -231,7 +231,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
 }
 @end
 
-@implementation Child // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation Child // expected-warning {{auto property synthesis will not synthesize property 'ObjB' declared in protocol 'IDEBuildable'}}
 - (void)invalidate{ 
   // no-warning
 } 
diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m
index 9c33b5bade9..3e9157d0961 100644
--- a/test/SemaObjC/attr-deprecated.m
+++ b/test/SemaObjC/attr-deprecated.m
@@ -201,7 +201,7 @@ expected-note {{'setObject:' has been explicitly marked deprecated here}}
 @end
 
 @interface TestDerived : TestBase
-@property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object' because it will be implemented by its superclass}}
+@property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object'; it will be implemented by its superclass}}
 @end
 
 @interface TestUse @end
diff --git a/test/SemaObjC/default-synthesize-1.m b/test/SemaObjC/default-synthesize-1.m
index 3ca34e027cb..2a34a65a957 100644
--- a/test/SemaObjC/default-synthesize-1.m
+++ b/test/SemaObjC/default-synthesize-1.m
@@ -132,7 +132,7 @@
 
 @interface ZXCalendarParsedResult : ZXParsedResult
 
-@property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description' because it will be implemented by its superclass}}
+@property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description'; it will be implemented by its superclass}}
 
 @end
 
diff --git a/test/SemaObjC/default-synthesize.m b/test/SemaObjC/default-synthesize.m
index 4865668af38..d0d3085ba70 100644
--- a/test/SemaObjC/default-synthesize.m
+++ b/test/SemaObjC/default-synthesize.m
@@ -88,7 +88,7 @@
 @end
 
 @protocol TopProtocol
-  @property (readonly) id myString; // expected-warning {{auto property synthesis will not synthesize property 'myString' because it will be implemented by its superclass}}
+  @property (readonly) id myString; // expected-note {{property declared here}}
 @end
 
 @interface TopClass <TopProtocol> 
@@ -100,7 +100,7 @@
 @interface SubClass : TopClass <TopProtocol>
 @end
 
-@implementation SubClass @end  // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation SubClass @end // expected-warning {{auto property synthesis will not synthesize property 'myString' declared in protocol 'TopProtocol'}}
 
 // rdar://7920807
 @interface C @end
@@ -138,3 +138,25 @@
  
 @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}}
 @end
+
+// rdar://18152478
+@protocol NSObject @end
+@protocol TMSourceManagerDelegate<NSObject>
+@end
+
+@protocol TMSourceManager <NSObject>
+@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+@end
+
+@interface TMSourceManager
+@property (nonatomic, assign) id <TMSourceManagerDelegate> delegate;
+@end
+
+@protocol TMTimeZoneManager <TMSourceManager>
+@end
+
+@interface TimeZoneManager : TMSourceManager <TMTimeZoneManager>
+@end
+
+@implementation TimeZoneManager
+@end
diff --git a/test/SemaObjC/protocols-suppress-conformance.m b/test/SemaObjC/protocols-suppress-conformance.m
index 855d2e96ef6..8415154ab1d 100644
--- a/test/SemaObjC/protocols-suppress-conformance.m
+++ b/test/SemaObjC/protocols-suppress-conformance.m
@@ -5,8 +5,7 @@
 __attribute__((objc_protocol_requires_explicit_implementation))
 @protocol Protocol
 - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
-@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} \
-					 // expected-warning 2 {{auto property synthesis will not synthesize property 'theWorstOfTimes'}}
+@property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} 
 @end
 
 // In this example, ClassA adopts the protocol.  We won't
@@ -21,8 +20,7 @@ __attribute__((objc_protocol_requires_explicit_implementation))
 @interface ClassB : ClassA <Protocol>
 @end
 
-@implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} \
-		      // expected-note {{detected while default synthesizing properties in class implementation}}
+@implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} 
 @end
 
 @interface ClassB_Good : ClassA <Protocol>
@@ -34,7 +32,7 @@ __attribute__((objc_protocol_requires_explicit_implementation))
 @end
 
 @interface ClassB_AlsoGood : ClassA <Protocol>
-@property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes' because it will be implemented by its superclass}}
+@property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes'; it will be implemented by its superclass}}
 @end
 
 // Default synthesis acts as if @dynamic
@@ -42,7 +40,7 @@ __attribute__((objc_protocol_requires_explicit_implementation))
 // it is declared in ClassA.  This is okay, since
 // the author of ClassB_AlsoGood needs explicitly
 // write @property in the @interface.
-@implementation ClassB_AlsoGood  // expected-note 2 {{detected while default synthesizing properties in class implementation}}
+@implementation ClassB_AlsoGood  // expected-note {{detected while default synthesizing properties in class implementation}}
 - (void) theBestOfTimes {}
 @end
 
diff --git a/test/SemaObjC/super-property-notation.m b/test/SemaObjC/super-property-notation.m
index 7cefe09b1e7..62ff93cb2b0 100644
--- a/test/SemaObjC/super-property-notation.m
+++ b/test/SemaObjC/super-property-notation.m
@@ -41,7 +41,7 @@ __attribute__((objc_root_class)) @interface ClassBase
 @end
 
 @interface ClassDerived : ClassBase 
-@property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo' because it will be implemented by its superclass}}
+@property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo'; it will be implemented by its superclass}}
 @end
 
 @implementation ClassDerived // expected-note {{detected while default synthesizing properties in class implementation}}
-- 
GitLab