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/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