Make code-completion for Objective-C message sends to "id" work in the
presence of precompiled headers by forcibly loading all of the
methods we know about from the PCH file before constructing our
code-completion list.

llvm-svn: 100535
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index d29cab4..ac56fab 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -13,6 +13,7 @@
 #include "Sema.h"
 #include "Lookup.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/ExternalSemaSource.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/Lex/MacroInfo.h"
@@ -2977,13 +2978,26 @@
   else if (FName->isStr("id")) {
     // We're messaging "id" as a type; provide all class/factory methods.
 
-    // FIXME: Load the entire class method pool from the PCH file
+    // If we have an external source, load the entire class method
+    // pool from the PCH file.
+    if (ExternalSource) {
+      for (uint32_t I = 0, N = ExternalSource->GetNumKnownSelectors(); I != N;
+           ++I) {
+        Selector Sel = ExternalSource->GetSelector(I);
+        if (Sel.isNull() || FactoryMethodPool.count(Sel) || 
+            InstanceMethodPool.count(Sel))
+          continue;
+
+        ReadMethodPool(Sel, /*isInstance=*/false);
+      }
+    }
+
     for (llvm::DenseMap<Selector, ObjCMethodList>::iterator
            M = FactoryMethodPool.begin(),
            MEnd = FactoryMethodPool.end();
          M != MEnd;
          ++M) {
-      for (ObjCMethodList *MethList = &M->second; MethList; 
+      for (ObjCMethodList *MethList = &M->second; MethList && MethList->Method; 
            MethList = MethList->Next) {
         if (!isAcceptableObjCMethod(MethList->Method, MK_Any, SelIdents, 
                                     NumSelIdents))
@@ -3056,13 +3070,29 @@
   }
   // Handle messages to "id".
   else if (ReceiverType->isObjCIdType()) {
-    // FIXME: Load the entire instance method pool from the PCH file
+    // We're messaging "id", so provide all instance methods we know
+    // about as code-completion results.
+
+    // If we have an external source, load the entire class method
+    // pool from the PCH file.
+    if (ExternalSource) {
+      for (uint32_t I = 0, N = ExternalSource->GetNumKnownSelectors(); I != N;
+           ++I) {
+        Selector Sel = ExternalSource->GetSelector(I);
+        if (Sel.isNull() || InstanceMethodPool.count(Sel) ||
+            FactoryMethodPool.count(Sel))
+          continue;
+
+        ReadMethodPool(Sel, /*isInstance=*/true);
+      }
+    }
+
     for (llvm::DenseMap<Selector, ObjCMethodList>::iterator
            M = InstanceMethodPool.begin(),
            MEnd = InstanceMethodPool.end();
          M != MEnd;
          ++M) {
-      for (ObjCMethodList *MethList = &M->second; MethList; 
+      for (ObjCMethodList *MethList = &M->second; MethList && MethList->Method; 
            MethList = MethList->Next) {
         if (!isAcceptableObjCMethod(MethList->Method, MK_Any, SelIdents, 
                                     NumSelIdents))