Fix <rdar://problem/5986833> clang on xcode: incompatible type returning 'void', expected 'int'.

- Changed Sema::ObjCActOnStartOfMethodDef() to more accurately type "self" in factory methods.
- Changed Sema::ActOnInstanceMessage() to use the new type to restrict the lookup.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52005 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 795e356..3117f87 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -42,15 +42,17 @@
   // Insert the invisible arguments, self and _cmd!
   PI.Ident = &Context.Idents.get("self");
   PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
-  QualType selfTy = Context.getObjCIdType();
+  QualType selfTy;
   if (MDecl->isInstance()) {
+    selfTy = Context.getObjCIdType();
     if (ObjCInterfaceDecl *OID = MDecl->getClassInterface()) {
       // There may be no interface context due to error in declaration of the 
       // interface (which has been reported). Recover gracefully
       selfTy = Context.getObjCInterfaceType(OID);
       selfTy = Context.getPointerType(selfTy);
     }
-  }
+  } else // we have a factory method.
+    selfTy = Context.getObjCClassType();
   CurMethodDecl->setSelfDecl(CreateImplicitParameter(FnBodyScope, PI.Ident, 
                                                      PI.IdentLoc, selfTy));
   
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index e2e23ce..1f21ee0 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -223,8 +223,7 @@
 
   receiverType = RExpr->getType().getCanonicalType().getUnqualifiedType();
   
-  if (receiverType == Context.getObjCIdType().getCanonicalType() ||
-      receiverType == Context.getObjCClassType().getCanonicalType()) {
+  if (receiverType == Context.getObjCIdType().getCanonicalType()) {
     Method = InstanceMethodPool[Sel].Method;
     if (!Method)
       Method = FactoryMethodPool[Sel].Method;
@@ -238,6 +237,29 @@
         if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
           return true;
     }
+  } else if (receiverType == Context.getObjCClassType().getCanonicalType()) {
+    if (CurMethodDecl) {
+      ObjCInterfaceDecl* ClassDecl = CurMethodDecl->getClassInterface();
+      // If we have an implementation in scope, check "private" methods.
+      if (ClassDecl)
+        if (ObjCImplementationDecl *ImpDecl = 
+            ObjCImplementations[ClassDecl->getIdentifier()])
+          Method = ImpDecl->getClassMethod(Sel);
+    }
+    if (!Method)
+      Method = FactoryMethodPool[Sel].Method;
+    if (!Method)
+      Method = InstanceMethodPool[Sel].Method;
+    if (!Method) {
+      Diag(lbrac, diag::warn_method_not_found, std::string("-"), Sel.getName(),
+           SourceRange(lbrac, rbrac));
+      returnType = Context.getObjCIdType();
+    } else {
+      returnType = Method->getResultType();
+      if (Sel.getNumArgs())
+        if (CheckMessageArgumentTypes(ArgExprs, Sel.getNumArgs(), Method))
+          return true;
+    }
   } else {
     bool receiverIsQualId = isa<ObjCQualifiedIdType>(receiverType);
     // FIXME (snaroff): checking in this code from Patrick. Needs to be