In objc2's None-Fragile ABI, one cannot use the super class ivar for
setter/getter synthesis.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68976 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index cf782ca..d468c13 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1791,11 +1791,13 @@
   // Check that we have a valid, previously declared ivar for @synthesize
   if (Synthesize) {
     // @synthesize
+    bool NoExplicitPropertyIvar = (!PropertyIvar);
     if (!PropertyIvar)
       PropertyIvar = PropertyId;
     QualType PropType = Context.getCanonicalType(property->getType());
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
-    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar);
+    ObjCInterfaceDecl *ClassDeclared;
+    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar, ClassDeclared);
     if (!Ivar) {
       if (getLangOptions().ObjCNonFragileABI) {
         Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, 
@@ -1809,6 +1811,15 @@
         return DeclPtrTy();
       }
     }
+    else if (getLangOptions().ObjCNonFragileABI &&
+             NoExplicitPropertyIvar && ClassDeclared != IDecl) {
+      Diag(PropertyLoc, diag::error_ivar_in_superclass_use)
+        << property->getDeclName() << Ivar->getDeclName() 
+        << ClassDeclared->getDeclName();
+      Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
+        << Ivar << Ivar->getNameAsCString();
+      // Note! I deliberately want it to fall thru so more errors are caught.
+    }
     QualType IvarType = Context.getCanonicalType(Ivar->getType());
     
     // Check that type of property and its ivar are type compatible.