Fix a corner case of message lookup looking for class methods.
If all else failed, find the message in class's root's
list of instacne methods!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66040 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 8705baf..80120a7 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -314,8 +314,14 @@
     Method = LookupPrivateMethod(Sel, ClassDecl);
 
   // Before we give up, check if the selector is an instance method.
-  if (!Method)
-    Method = ClassDecl->lookupInstanceMethod(Sel);
+  // But only in the root. This matches gcc's behaviour and what the
+  // runtime expects.
+  if (!Method) {
+    ObjCInterfaceDecl *Root = ClassDecl;
+    while (Root->getSuperClass())
+      Root = Root->getSuperClass(); 
+    Method = Root->lookupInstanceMethod(Sel);
+  }
 
   if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
     return true;
@@ -400,6 +406,15 @@
         
         if (!Method)
           Method = LookupPrivateMethod(Sel, ClassDecl);
+        // Before we give up, check if the selector is an instance method.
+        // But only in the root. This matches gcc's behaviour and what the
+        // runtime expects.
+        if (!Method) {
+          ObjCInterfaceDecl *Root = ClassDecl;
+          while (Root->getSuperClass())
+            Root = Root->getSuperClass();
+          Method = Root->lookupInstanceMethod(Sel);
+        }
       }
       if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
         return true;
@@ -408,9 +423,12 @@
       // If not messaging 'self', look for any factory method named 'Sel'.
       if (!isSelfExpr(RExpr)) {
         Method = FactoryMethodPool[Sel].Method;
-        if (!Method)
+        if (!Method) {
           Method = LookupInstanceMethodInGlobalPool(
                                    Sel, SourceRange(lbrac,rbrac));
+          if (Method)
+            Diag(receiverLoc, diag::warn_maynot_respond) << Sel;
+        }
       }
     }
     if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false,