Fix <rdar://problem/6500554> missing objc error message.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65198 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index c7f37fc..dfa1e03 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1470,8 +1470,7 @@
     CheckExtraCXXDefaultArguments(D);
 
   if (R.getTypePtr()->isObjCInterfaceType()) {
-    Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object)
-      << D.getIdentifier();
+    Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object);
     InvalidDecl = true;
   }
 
@@ -2761,6 +2760,13 @@
       << D.getCXXScopeSpec().getRange();
     New->setInvalidDecl();
   }
+  // Parameter declarators cannot be interface types. All ObjC objects are
+  // passed by reference.
+  if (parmDeclType->isObjCInterfaceType()) {
+    Diag(D.getIdentifierLoc(), diag::err_object_cannot_be_by_value) 
+         << "passed";
+    New->setInvalidDecl();
+  }
 
   // Add the parameter declaration into this scope.
   S->AddDecl(New);
@@ -3671,8 +3677,7 @@
     }
     /// A field cannot be an Objective-c object
     if (FDTy->isObjCInterfaceType()) {
-      Diag(FD->getLocation(), diag::err_statically_allocated_object)
-        << FD->getDeclName();
+      Diag(FD->getLocation(), diag::err_statically_allocated_object);
       FD->setInvalidDecl();
       EnclosingDecl->setInvalidDecl();
       continue;
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 967094a..660f745 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1344,9 +1344,17 @@
   }
   QualType resultDeclType;
   
-  if (ReturnType)
+  if (ReturnType) {
     resultDeclType = QualType::getFromOpaquePtr(ReturnType);
-  else // get the type for "id".
+    
+    // Methods cannot return interface types. All ObjC objects are
+    // passed by reference.
+    if (resultDeclType->isObjCInterfaceType()) {
+      Diag(MethodLoc, diag::err_object_cannot_be_by_value)
+           << "returned";
+      return 0;
+    }
+  } else // get the type for "id".
     resultDeclType = Context.getObjCIdType();
   
   ObjCMethodDecl* ObjCMethod = 
@@ -1375,7 +1383,9 @@
         argType = Context.getPointerType(argType);
       else if (argType->isObjCInterfaceType()) {
         // FIXME! provide more precise location for the parameter
-        Diag(MethodLoc, diag::err_object_as_method_param);
+        Diag(MethodLoc, diag::err_object_cannot_be_by_value)
+             << "passed";
+        ObjCMethod->setInvalidDecl();
         return 0;
       }
     } else