More semantics checks of properties. Property implementation can implicitly use
ivar of same name. 
Better diagnostics to bring home this point.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50065 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 4f46eaa..a8560e1 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -492,7 +492,7 @@
 DIAG(error_bad_property_context, ERROR,
      "property implementation must be in a class or category implementation")
 DIAG(error_bad_property_decl, ERROR,
-     "property implementation must have its declaration in the class '%0'")
+     "property implementation must have its declaration in interface '%0'")
 DIAG(error_bad_category_property_decl, ERROR,
      "property implementation must have its declaration in the category '%0'")
 DIAG(error_property_ivar_decl, ERROR,
@@ -502,7 +502,8 @@
 DIAG(error_missing_property_interface, ERROR,
      "property implementation in a category with no category declaration")
 DIAG(error_missing_property_ivar_decl, ERROR,
-     "property synthesize requires a previously declared ivar")
+     "synthesized property '%0' must either be named the same as a compatible"
+     " ivar or must explicitly name an ivar")
 DIAG(error_synthesize_category_decl, ERROR,
      "@synthesize not allowed in a category's implementation")
 DIAG(error_property_ivar_type, ERROR,
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 45d8777..234bead 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -998,14 +998,13 @@
   // Check that we have a valid, previously declared ivar for @synthesize
   if (Synthesize) {
     // @synthesize
-    if (!PropertyIvar) {
-      Diag(PropertyLoc, diag::error_property_ivar_decl);
-      return 0;
-    }
+    if (!PropertyIvar)
+      PropertyIvar = PropertyId;
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
     ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
     if (!Ivar) {
-      Diag(PropertyLoc, diag::error_missing_property_ivar_decl);
+      Diag(PropertyLoc, diag::error_missing_property_ivar_decl, 
+           PropertyId->getName());
       return 0;
     }
     // Check that type of property and its ivar match. 
diff --git a/test/Sema/objc-property-1.m b/test/Sema/objc-property-1.m
index d307d13..3bc2e33 100644
--- a/test/Sema/objc-property-1.m
+++ b/test/Sema/objc-property-1.m
@@ -3,9 +3,11 @@
 @interface I 
 {
 	int IVAR;
+	int name;
 }
 @property int d1;
 @property id  prop_id;
+@property int name;
 @end
 
 @interface I(CAT)
@@ -13,10 +15,11 @@
 @end
 
 @implementation I
-@synthesize d1;		// expected-error {{property synthesize requires specification of an ivar}}
-@dynamic    bad;	// expected-error {{property implementation must have its declaration in the class 'I'}}
-@synthesize prop_id;	// expected-error {{property synthesize requires specification of an ivar}}
+@synthesize d1;		// expected-error {{synthesized property 'd1' must either be named the same as}}
+@dynamic    bad;	// expected-error {{property implementation must have its declaration in interface 'I'}}
+@synthesize prop_id;	// expected-error {{synthesized property 'prop_id' must either be named the same}}
 @synthesize prop_id = IVAR;	// expected-error {{type of property 'prop_id'  does not match type of ivar 'IVAR'}}
+@synthesize name;	// OK! property with same name as an accessible ivar of same name
 @end
 
 @implementation I(CAT)
@@ -25,7 +28,7 @@
 @end
 
 @implementation E	// expected-warning {{cannot find interface declaration for 'E'}}
-@dynamic d;		// expected-error {{property implementation must have its declaration in the class 'E'}}
+@dynamic d;		// expected-error {{property implementation must have its declaration in interface 'E'}}
 @end
 
 @implementation Q(MYCAT)  // expected-error {{cannot find interface declaration for 'Q'}}