When suggesting a module import for a #include or #import, suggest the
most specific (sub)module based on the actual file we find, rather
than always importing the top-level module. This means
that #include'ing <Foo/Blah.h> should give us the submodule Foo.Blah.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145942 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp
index 1d560fc..f090e03 100644
--- a/lib/Lex/HeaderSearch.cpp
+++ b/lib/Lex/HeaderSearch.cpp
@@ -341,15 +341,12 @@
   }
 
   // Determine whether this is the module we're building or not.
-  // FIXME: Do we still need the ".." hack?
-  bool AutomaticImport = Module &&
-    !Filename.substr(SlashPos + 1).startswith("..");
-  
+  bool AutomaticImport = Module;  
   FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
   if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
                                             /*openFile=*/!AutomaticImport)) {
     if (AutomaticImport)
-      *SuggestedModule = Module;
+      *SuggestedModule = HS.findModuleForHeader(FE);
     return FE;
   }
 
@@ -364,7 +361,7 @@
   const FileEntry *FE = FileMgr.getFile(FrameworkName.str(), 
                                         /*openFile=*/!AutomaticImport);
   if (FE && AutomaticImport)
-    *SuggestedModule = Module;
+    *SuggestedModule = HS.findModuleForHeader(FE);
   return FE;
 }