objective-c: warn if implementation of a method in category
masks an existing method in its primary class, class extensions,
and primary class's non-optional protocol methods; as primary
class, or one of its subclass's will implement this method.
This warning has potential of being noisy so it has its own
group.  // rdar://7020493


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136426 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m
index 49dd8a6..824fc08 100644
--- a/test/SemaObjC/arc.m
+++ b/test/SemaObjC/arc.m
@@ -41,10 +41,10 @@
 // rdar://8843638
 
 @interface I
-- (id)retain;
-- (id)autorelease;
-- (oneway void)release;
-- (NSUInteger)retainCount;
+- (id)retain; // expected-note {{method declared here}}
+- (id)autorelease; // expected-note {{method declared here}}
+- (oneway void)release; // expected-note {{method declared here}}
+- (NSUInteger)retainCount; // expected-note {{method declared here}}
 @end
 
 @implementation I
@@ -55,10 +55,14 @@
 @end
 
 @implementation I(CAT)
-- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
-- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
-- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
-- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
+- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} \
+                        // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} \
+                         // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} \
+                          // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} \
+                          // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
 @end
 
 // rdar://8861761
diff --git a/test/SemaObjC/incomplete-implementation.m b/test/SemaObjC/incomplete-implementation.m
index 612c331..f5c5a7c 100644
--- a/test/SemaObjC/incomplete-implementation.m
+++ b/test/SemaObjC/incomplete-implementation.m
@@ -1,26 +1,27 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 @interface I
-- Meth; // expected-note{{method definition for 'Meth' not found}}
+- Meth; // expected-note{{method definition for 'Meth' not found}} \
+        // expected-note{{method declared here}}
 @end
 
 @implementation  I  // expected-warning{{incomplete implementation}}
 @end
 
 @implementation I(CAT)
-- Meth {return 0;}
+- Meth {return 0;} // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
 @end
 
 #pragma GCC diagnostic ignored "-Wincomplete-implementation"
 @interface I2
-- Meth;
+- Meth; // expected-note{{method declared here}}
 @end
 
 @implementation  I2
 @end
 
 @implementation I2(CAT)
-- Meth {return 0;}
+- Meth {return 0;} // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
 @end
 
 
diff --git a/test/SemaObjC/protocol-implementing-class-methods.m b/test/SemaObjC/protocol-implementing-class-methods.m
new file mode 100644
index 0000000..6d68e8c
--- /dev/null
+++ b/test/SemaObjC/protocol-implementing-class-methods.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1  -fsyntax-only -verify %s
+// rdar://7020493
+
+@protocol P1
+@optional
+- (int) PMeth;
+@required
+- (void) : (double) arg; // expected-note {{method declared here}}
+@end
+
+@interface NSImage <P1>
+- (void) initialize; // expected-note {{method declared here}}
+@end
+
+@interface NSImage (AirPortUI)
+- (void) initialize;
+@end
+
+@interface NSImage()
+- (void) CEMeth; // expected-note {{method declared here}}
+@end
+
+@implementation NSImage (AirPortUI)
+- (void) initialize {NSImage *p=0; [p initialize]; } // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+- (int) PMeth{ return 0; }
+- (void) : (double) arg{}; // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+- (void) CEMeth {}; // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
+@end
diff --git a/test/SemaObjC/related-result-type-inference.m b/test/SemaObjC/related-result-type-inference.m
index 094f19a..11b4b96 100644
--- a/test/SemaObjC/related-result-type-inference.m
+++ b/test/SemaObjC/related-result-type-inference.m
@@ -149,8 +149,8 @@
 @end
 
 // <rdar://problem/9340699>
-@interface G
-- (id)_ABC_init __attribute__((objc_method_family(init)));
+@interface G 
+- (id)_ABC_init __attribute__((objc_method_family(init))); // expected-note {{method declared here}}
 @end
 
 @interface G (Additions)
@@ -158,7 +158,7 @@
 @end
 
 @implementation G (Additions)
-- (id)_ABC_init {
+- (id)_ABC_init { // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
   return 0;
 }
 - (id)_ABC_init2 {