When generating includes for all of the headers we found in an
umbrella directory, skip includes for any headers that are part of an
unavailable module.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147572 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index d9a385d..2261b30 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -134,6 +134,8 @@
 /// \param Includes Will be augmented with the set of #includes or #imports
 /// needed to load all of the named headers.
 static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
+                                        FileManager &FileMgr,
+                                        ModuleMap &ModMap,
                                         clang::Module *Module,
                                         llvm::SmallString<256> &Includes) {
   // Don't collect any headers for unavailable modules.
@@ -161,7 +163,7 @@
       Includes += "\"\n";
     }
   } else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) {
-    // Add all of the headers we find in this subdirectory (FIXME: recursively!).
+    // Add all of the headers we find in this subdirectory.
     llvm::error_code EC;
     llvm::SmallString<128> DirNative;
     llvm::sys::path::native(UmbrellaDir->getName(), DirNative);
@@ -175,6 +177,12 @@
           .Default(false))
         continue;
       
+      // If this header is marked 'unavailable' in this module, don't include 
+      // it.
+      if (const FileEntry *Header = FileMgr.getFile(Dir->path()))
+        if (ModMap.isHeaderInUnavailableModule(Header))
+          continue;
+      
       // Include this header umbrella header for submodules.
       if (LangOpts.ObjC1)
         Includes += "#import \"";
@@ -189,7 +197,7 @@
   for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
                                       SubEnd = Module->submodule_end();
        Sub != SubEnd; ++Sub)
-    collectModuleHeaderIncludes(LangOpts, *Sub, Includes);
+    collectModuleHeaderIncludes(LangOpts, FileMgr, ModMap, *Sub, Includes);
 }
 
 bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, 
@@ -241,7 +249,9 @@
   
   // Collect the set of #includes we need to build the module.
   llvm::SmallString<256> HeaderContents;
-  collectModuleHeaderIncludes(CI.getLangOpts(), Module, HeaderContents);
+  collectModuleHeaderIncludes(CI.getLangOpts(), CI.getFileManager(),
+    CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(),
+    Module, HeaderContents);
   if (UmbrellaHeader && HeaderContents.empty()) {
     // Simple case: we have an umbrella header and there are no additional
     // includes, we can just parse the umbrella header directly.
diff --git a/test/Modules/Inputs/NoUmbrella.framework/Headers/Boom.h b/test/Modules/Inputs/NoUmbrella.framework/Headers/Boom.h
new file mode 100644
index 0000000..ac4a14a
--- /dev/null
+++ b/test/Modules/Inputs/NoUmbrella.framework/Headers/Boom.h
@@ -0,0 +1 @@
+this is gibberish
diff --git a/test/Modules/Inputs/NoUmbrella.framework/module.map b/test/Modules/Inputs/NoUmbrella.framework/module.map
index 9441501..986cca9 100644
--- a/test/Modules/Inputs/NoUmbrella.framework/module.map
+++ b/test/Modules/Inputs/NoUmbrella.framework/module.map
@@ -1,4 +1,9 @@
 framework module NoUmbrella {
   umbrella "Headers"
   module * { }
-}
\ No newline at end of file
+
+  module unavailable {
+    requires unavailable
+    header "Boom.h"
+  }
+}