diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:47:56 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:47:56 +0000 | 
| commit | 5e20cdd81c44a443562a09007668ffdf76c455af (patch) | |
| tree | dbbd4047878da71c1a706e26ce05b4e7791b14cc /lib/Frontend/CompilerInstance.cpp | |
| parent | d5f23b0b7528b5c3caed1ba14f897cc4aaa9e3c3 (diff) | |
Notes
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
| -rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 330 | 
1 files changed, 168 insertions, 162 deletions
| diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 93a34b7222744..9e017273cb2a9 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -329,14 +329,8 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {    PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP); -  // Set up the module path, including the hash for the -  // module-creation options. -  SmallString<256> SpecificModuleCache( -                           getHeaderSearchOpts().ModuleCachePath); -  if (!getHeaderSearchOpts().DisableModuleHash) -    llvm::sys::path::append(SpecificModuleCache, -                            getInvocation().getModuleHash()); -  PP->getHeaderSearchInfo().setModuleCachePath(SpecificModuleCache); +  if (PP->getLangOpts().Modules) +    PP->getHeaderSearchInfo().setModuleCachePath(getSpecificModuleCachePath());    // Handle generating dependencies, if requested.    const DependencyOutputOptions &DepOpts = getDependencyOutputOpts(); @@ -371,14 +365,17 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {      AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"",                             /*ShowDepth=*/true, /*MSStyle=*/true);    } +} -  // Load all explictly-specified module map files. -  for (const auto &Filename : getFrontendOpts().ModuleMapFiles) { -    if (auto *File = getFileManager().getFile(Filename)) -      PP->getHeaderSearchInfo().loadModuleMapFile(File, /*IsSystem*/false); -    else -      getDiagnostics().Report(diag::err_module_map_not_found) << Filename; -  } +std::string CompilerInstance::getSpecificModuleCachePath() { +  // Set up the module path, including the hash for the +  // module-creation options. +  SmallString<256> SpecificModuleCache( +                           getHeaderSearchOpts().ModuleCachePath); +  if (!getHeaderSearchOpts().DisableModuleHash) +    llvm::sys::path::append(SpecificModuleCache, +                            getInvocation().getModuleHash()); +  return SpecificModuleCache.str();  }  // ASTContext @@ -396,32 +393,30 @@ void CompilerInstance::createASTContext() {  void CompilerInstance::createPCHExternalASTSource(      StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors,      void *DeserializationListener, bool OwnDeserializationListener) { -  IntrusiveRefCntPtr<ExternalASTSource> Source;    bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; -  Source = createPCHExternalASTSource( +  ModuleManager = createPCHExternalASTSource(        Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation,        AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(),        DeserializationListener, OwnDeserializationListener, Preamble,        getFrontendOpts().UseGlobalModuleIndex); -  ModuleManager = static_cast<ASTReader*>(Source.get()); -  getASTContext().setExternalSource(Source);  } -ExternalASTSource *CompilerInstance::createPCHExternalASTSource( +IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(      StringRef Path, const std::string &Sysroot, bool DisablePCHValidation,      bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,      void *DeserializationListener, bool OwnDeserializationListener,      bool Preamble, bool UseGlobalModuleIndex) {    HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); -  std::unique_ptr<ASTReader> Reader; -  Reader.reset(new ASTReader(PP, Context, -                             Sysroot.empty() ? "" : Sysroot.c_str(), -                             DisablePCHValidation, -                             AllowPCHWithCompilerErrors, -                             /*AllowConfigurationMismatch*/false, -                             HSOpts.ModulesValidateSystemHeaders, -                             UseGlobalModuleIndex)); +  IntrusiveRefCntPtr<ASTReader> Reader( +      new ASTReader(PP, Context, Sysroot.empty() ? "" : Sysroot.c_str(), +                    DisablePCHValidation, AllowPCHWithCompilerErrors, +                    /*AllowConfigurationMismatch*/ false, +                    HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex)); + +  // We need the external source to be set up before we read the AST, because +  // eagerly-deserialized declarations may use it. +  Context.setExternalSource(Reader.get());    Reader->setDeserializationListener(        static_cast<ASTDeserializationListener *>(DeserializationListener), @@ -435,7 +430,7 @@ ExternalASTSource *CompilerInstance::createPCHExternalASTSource(      // Set the predefines buffer as suggested by the PCH reader. Typically, the      // predefines buffer will be empty.      PP.setPredefines(Reader->getSuggestedPredefines()); -    return Reader.release(); +    return Reader;    case ASTReader::Failure:      // Unrecoverable failure: don't even try to process the input file. @@ -450,6 +445,7 @@ ExternalASTSource *CompilerInstance::createPCHExternalASTSource(      break;    } +  Context.setExternalSource(nullptr);    return nullptr;  } @@ -522,42 +518,43 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind,  // Output Files -void CompilerInstance::addOutputFile(const OutputFile &OutFile) { +void CompilerInstance::addOutputFile(OutputFile &&OutFile) {    assert(OutFile.OS && "Attempt to add empty stream to output list!"); -  OutputFiles.push_back(OutFile); +  OutputFiles.push_back(std::move(OutFile));  }  void CompilerInstance::clearOutputFiles(bool EraseFiles) { -  for (std::list<OutputFile>::iterator -         it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) { -    delete it->OS; -    if (!it->TempFilename.empty()) { +  for (OutputFile &OF : OutputFiles) { +    // Manually close the stream before we rename it. +    OF.OS.reset(); + +    if (!OF.TempFilename.empty()) {        if (EraseFiles) { -        llvm::sys::fs::remove(it->TempFilename); +        llvm::sys::fs::remove(OF.TempFilename);        } else { -        SmallString<128> NewOutFile(it->Filename); +        SmallString<128> NewOutFile(OF.Filename);          // If '-working-directory' was passed, the output filename should be          // relative to that.          FileMgr->FixupRelativePath(NewOutFile);          if (std::error_code ec = -                llvm::sys::fs::rename(it->TempFilename, NewOutFile.str())) { +                llvm::sys::fs::rename(OF.TempFilename, NewOutFile)) {            getDiagnostics().Report(diag::err_unable_to_rename_temp) -            << it->TempFilename << it->Filename << ec.message(); +            << OF.TempFilename << OF.Filename << ec.message(); -          llvm::sys::fs::remove(it->TempFilename); +          llvm::sys::fs::remove(OF.TempFilename);          }        } -    } else if (!it->Filename.empty() && EraseFiles) -      llvm::sys::fs::remove(it->Filename); +    } else if (!OF.Filename.empty() && EraseFiles) +      llvm::sys::fs::remove(OF.Filename);    }    OutputFiles.clear(); +  NonSeekStream.reset();  } -llvm::raw_fd_ostream * -CompilerInstance::createDefaultOutputFile(bool Binary, -                                          StringRef InFile, +raw_pwrite_stream * +CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile,                                            StringRef Extension) {    return createOutputFile(getFrontendOpts().OutputFile, Binary,                            /*RemoveFileOnSignal=*/true, InFile, Extension, @@ -565,21 +562,20 @@ CompilerInstance::createDefaultOutputFile(bool Binary,  }  llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() { -  llvm::raw_null_ostream *OS = new llvm::raw_null_ostream(); -  addOutputFile(OutputFile("", "", OS)); -  return OS; +  auto OS = llvm::make_unique<llvm::raw_null_ostream>(); +  llvm::raw_null_ostream *Ret = OS.get(); +  addOutputFile(OutputFile("", "", std::move(OS))); +  return Ret;  } -llvm::raw_fd_ostream * -CompilerInstance::createOutputFile(StringRef OutputPath, -                                   bool Binary, bool RemoveFileOnSignal, -                                   StringRef InFile, -                                   StringRef Extension, -                                   bool UseTemporary, +raw_pwrite_stream * +CompilerInstance::createOutputFile(StringRef OutputPath, bool Binary, +                                   bool RemoveFileOnSignal, StringRef InFile, +                                   StringRef Extension, bool UseTemporary,                                     bool CreateMissingDirectories) {    std::string OutputPathName, TempPathName;    std::error_code EC; -  llvm::raw_fd_ostream *OS = createOutputFile( +  std::unique_ptr<raw_pwrite_stream> OS = createOutputFile(        OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension,        UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName);    if (!OS) { @@ -588,15 +584,16 @@ CompilerInstance::createOutputFile(StringRef OutputPath,      return nullptr;    } +  raw_pwrite_stream *Ret = OS.get();    // Add the output file -- but don't try to remove "-", since this means we are    // using stdin.    addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", -                TempPathName, OS)); +                           TempPathName, std::move(OS))); -  return OS; +  return Ret;  } -llvm::raw_fd_ostream *CompilerInstance::createOutputFile( +std::unique_ptr<llvm::raw_pwrite_stream> CompilerInstance::createOutputFile(      StringRef OutputPath, std::error_code &Error, bool Binary,      bool RemoveFileOnSignal, StringRef InFile, StringRef Extension,      bool UseTemporary, bool CreateMissingDirectories, @@ -646,14 +643,14 @@ llvm::raw_fd_ostream *CompilerInstance::createOutputFile(      TempPath += "-%%%%%%%%";      int fd;      std::error_code EC = -        llvm::sys::fs::createUniqueFile(TempPath.str(), fd, TempPath); +        llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath);      if (CreateMissingDirectories &&          EC == llvm::errc::no_such_file_or_directory) {        StringRef Parent = llvm::sys::path::parent_path(OutputPath);        EC = llvm::sys::fs::create_directories(Parent);        if (!EC) { -        EC = llvm::sys::fs::createUniqueFile(TempPath.str(), fd, TempPath); +        EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath);        }      } @@ -684,7 +681,13 @@ llvm::raw_fd_ostream *CompilerInstance::createOutputFile(    if (TempPathName)      *TempPathName = TempFile; -  return OS.release(); +  if (!Binary || OS->supportsSeeking()) +    return std::move(OS); + +  auto B = llvm::make_unique<llvm::buffer_ostream>(*OS); +  assert(!NonSeekStream); +  NonSeekStream = std::move(OS); +  return std::move(B);  }  // Initialization Utilities @@ -946,16 +949,18 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance,      FrontendOpts.Inputs.push_back(          FrontendInputFile(ModuleMapFile->getName(), IK));    } else { +    SmallString<128> FakeModuleMapFile(Module->Directory->getName()); +    llvm::sys::path::append(FakeModuleMapFile, "__inferred_module.map"); +    FrontendOpts.Inputs.push_back(FrontendInputFile(FakeModuleMapFile, IK)); +      llvm::raw_string_ostream OS(InferredModuleMapContent);      Module->print(OS);      OS.flush(); -    FrontendOpts.Inputs.push_back( -        FrontendInputFile("__inferred_module.map", IK));      std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =          llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent);      ModuleMapFile = Instance.getFileManager().getVirtualFile( -        "__inferred_module.map", InferredModuleMapContent.size(), 0); +        FakeModuleMapFile, InferredModuleMapContent.size(), 0);      SourceMgr.overrideFileContents(ModuleMapFile, std::move(ModuleMapBuffer));    } @@ -1031,9 +1036,19 @@ static bool compileAndLoadModule(CompilerInstance &ImportingInstance,      case llvm::LockFileManager::LFS_Shared:        // Someone else is responsible for building the module. Wait for them to        // finish. -      if (Locked.waitForUnlock() == llvm::LockFileManager::Res_OwnerDied) +      switch (Locked.waitForUnlock()) { +      case llvm::LockFileManager::Res_Success: +        ModuleLoadCapabilities |= ASTReader::ARR_OutOfDate; +        break; +      case llvm::LockFileManager::Res_OwnerDied:          continue; // try again to get the lock. -      ModuleLoadCapabilities |= ASTReader::ARR_OutOfDate; +      case llvm::LockFileManager::Res_Timeout: +        Diags.Report(ModuleNameLoc, diag::err_module_lock_timeout) +            << Module->Name; +        // Clear the lock file so that future invokations can make progress. +        Locked.unsafeRemoveLockFile(); +        return false; +      }        break;      } @@ -1071,79 +1086,51 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro,    // not have changed.    if (!Id->hadMacroDefinition())      return; +  auto *LatestLocalMD = PP.getLocalMacroDirectiveHistory(Id); -  // If this identifier does not currently have a macro definition, -  // check whether it had one on the command line. -  if (!Id->hasMacroDefinition()) { -    MacroDirective::DefInfo LatestDef = -        PP.getMacroDirectiveHistory(Id)->getDefinition(); -    for (MacroDirective::DefInfo Def = LatestDef; Def; -           Def = Def.getPreviousDefinition()) { -      FileID FID = SourceMgr.getFileID(Def.getLocation()); -      if (FID.isInvalid()) -        continue; - -      // We only care about the predefines buffer. -      if (FID != PP.getPredefinesFileID()) -        continue; - -      // This macro was defined on the command line, then #undef'd later. -      // Complain. -      PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) -        << true << ConfigMacro << Mod->getFullModuleName(); -      if (LatestDef.isUndefined()) -        PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here) -          << true; -      return; -    } - -    // Okay: no definition in the predefines buffer. -    return; -  } - -  // This identifier has a macro definition. Check whether we had a definition -  // on the command line. -  MacroDirective::DefInfo LatestDef = -      PP.getMacroDirectiveHistory(Id)->getDefinition(); -  MacroDirective::DefInfo PredefinedDef; -  for (MacroDirective::DefInfo Def = LatestDef; Def; -         Def = Def.getPreviousDefinition()) { -    FileID FID = SourceMgr.getFileID(Def.getLocation()); -    if (FID.isInvalid()) -      continue; - +  // Find the macro definition from the command line. +  MacroInfo *CmdLineDefinition = nullptr; +  for (auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) {      // We only care about the predefines buffer. -    if (FID != PP.getPredefinesFileID()) +    FileID FID = SourceMgr.getFileID(MD->getLocation()); +    if (FID.isInvalid() || FID != PP.getPredefinesFileID())        continue; - -    PredefinedDef = Def; +    if (auto *DMD = dyn_cast<DefMacroDirective>(MD)) +      CmdLineDefinition = DMD->getMacroInfo();      break;    } -  // If there was no definition for this macro in the predefines buffer, -  // complain. -  if (!PredefinedDef || -      (!PredefinedDef.getLocation().isValid() && -       PredefinedDef.getUndefLocation().isValid())) { +  auto *CurrentDefinition = PP.getMacroInfo(Id); +  if (CurrentDefinition == CmdLineDefinition) { +    // Macro matches. Nothing to do. +  } else if (!CurrentDefinition) { +    // This macro was defined on the command line, then #undef'd later. +    // Complain. +    PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) +      << true << ConfigMacro << Mod->getFullModuleName(); +    auto LatestDef = LatestLocalMD->getDefinition(); +    assert(LatestDef.isUndefined() && +           "predefined macro went away with no #undef?"); +    PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here) +      << true; +    return; +  } else if (!CmdLineDefinition) { +    // There was no definition for this macro in the predefines buffer, +    // but there was a local definition. Complain.      PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)        << false << ConfigMacro << Mod->getFullModuleName(); -    PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here) +    PP.Diag(CurrentDefinition->getDefinitionLoc(), +            diag::note_module_def_undef_here) +      << false; +  } else if (!CurrentDefinition->isIdenticalTo(*CmdLineDefinition, PP, +                                               /*Syntactically=*/true)) { +    // The macro definitions differ. +    PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) +      << false << ConfigMacro << Mod->getFullModuleName(); +    PP.Diag(CurrentDefinition->getDefinitionLoc(), +            diag::note_module_def_undef_here)        << false; -    return;    } - -  // If the current macro definition is the same as the predefined macro -  // definition, it's okay. -  if (LatestDef.getMacroInfo() == PredefinedDef.getMacroInfo() || -      LatestDef.getMacroInfo()->isIdenticalTo(*PredefinedDef.getMacroInfo(),PP, -                                              /*Syntactically=*/true)) -    return; - -  // The macro definitions differ. -  PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) -    << false << ConfigMacro << Mod->getFullModuleName(); -  PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here) -    << false;  }  /// \brief Write a new timestamp file with the given path. @@ -1186,8 +1173,7 @@ static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {    std::error_code EC;    SmallString<128> ModuleCachePathNative;    llvm::sys::path::native(HSOpts.ModuleCachePath, ModuleCachePathNative); -  for (llvm::sys::fs::directory_iterator -         Dir(ModuleCachePathNative.str(), EC), DirEnd; +  for (llvm::sys::fs::directory_iterator Dir(ModuleCachePathNative, EC), DirEnd;         Dir != DirEnd && !EC; Dir.increment(EC)) {      // If we don't have a directory, there's nothing to look into.      if (!llvm::sys::fs::is_directory(Dir->path())) @@ -1235,9 +1221,10 @@ void CompilerInstance::createModuleManager() {      if (!hasASTContext())        createASTContext(); -    // If we're not recursively building a module, check whether we -    // need to prune the module cache. -    if (getSourceManager().getModuleBuildStack().empty() && +    // If we're implicitly building modules but not currently recursively +    // building a module, check whether we need to prune the module cache. +    if (getLangOpts().ImplicitModules && +        getSourceManager().getModuleBuildStack().empty() &&          getHeaderSearchOpts().ModuleCachePruneInterval > 0 &&          getHeaderSearchOpts().ModuleCachePruneAfter > 0) {        pruneModuleCache(getHeaderSearchOpts()); @@ -1274,6 +1261,7 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {    struct ReadModuleNames : ASTReaderListener {      CompilerInstance &CI;      std::vector<StringRef> ModuleFileStack; +    std::vector<StringRef> ModuleNameStack;      bool Failed;      bool TopFileIsModule; @@ -1283,21 +1271,36 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {      bool needsImportVisitation() const override { return true; }      void visitImport(StringRef FileName) override { +      if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second) { +        if (ModuleFileStack.size() == 0) +          TopFileIsModule = true; +        return; +      } +        ModuleFileStack.push_back(FileName); +      ModuleNameStack.push_back(StringRef());        if (ASTReader::readASTFileControlBlock(FileName, CI.getFileManager(),                                               *this)) { -        CI.getDiagnostics().Report(SourceLocation(), -                                   diag::err_module_file_not_found) +        CI.getDiagnostics().Report( +            SourceLocation(), CI.getFileManager().getBufferForFile(FileName) +                                  ? diag::err_module_file_invalid +                                  : diag::err_module_file_not_found)              << FileName; -        // FIXME: Produce a note stack explaining how we got here. +        for (int I = ModuleFileStack.size() - 2; I >= 0; --I) +          CI.getDiagnostics().Report(SourceLocation(), +                                     diag::note_module_file_imported_by) +              << ModuleFileStack[I] +              << !ModuleNameStack[I].empty() << ModuleNameStack[I];          Failed = true;        } +      ModuleNameStack.pop_back();        ModuleFileStack.pop_back();      }      void ReadModuleName(StringRef ModuleName) override {        if (ModuleFileStack.size() == 1)          TopFileIsModule = true; +      ModuleNameStack.back() = ModuleName;        auto &ModuleFile = CI.ModuleFileOverrides[ModuleName];        if (!ModuleFile.empty() && @@ -1310,6 +1313,19 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {      }    } RMN(*this); +  // If we don't already have an ASTReader, create one now. +  if (!ModuleManager) +    createModuleManager(); + +  // Tell the module manager about this module file. +  if (getModuleManager()->getModuleManager().addKnownModuleFile(FileName)) { +    getDiagnostics().Report(SourceLocation(), diag::err_module_file_not_found) +      << FileName; +    return false; +  } + +  // Build our mapping of module names to module files from this file +  // and its imports.    RMN.visitImport(FileName);    if (RMN.Failed) @@ -1343,7 +1359,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,      if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule &&          ModuleName != getLangOpts().ImplementationOfModule)        ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility, -                                       ImportLoc, /*Complain=*/false); +                                       ImportLoc);      return LastModuleImportResult;    } @@ -1373,6 +1389,12 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,      auto Override = ModuleFileOverrides.find(ModuleName);      bool Explicit = Override != ModuleFileOverrides.end(); +    if (!Explicit && !getLangOpts().ImplicitModules) { +      getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) +          << ModuleName; +      ModuleBuildFailed = true; +      return ModuleLoadResult(); +    }      std::string ModuleFileName =          Explicit ? Override->second @@ -1580,8 +1602,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,        return ModuleLoadResult();      } -    ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc, -                                     /*Complain=*/true); +    ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc);    }    // Check for any configuration macros that have changed. @@ -1591,25 +1612,6 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,                       Module, ImportLoc);    } -  // Determine whether we're in the #include buffer for a module. The #includes -  // in that buffer do not qualify as module imports; they're just an -  // implementation detail of us building the module. -  bool IsInModuleIncludes = !getLangOpts().CurrentModule.empty() && -                            getSourceManager().getFileID(ImportLoc) == -                                getSourceManager().getMainFileID(); - -  // If this module import was due to an inclusion directive, create an  -  // implicit import declaration to capture it in the AST. -  if (IsInclusionDirective && hasASTContext() && !IsInModuleIncludes) { -    TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); -    ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, -                                                     ImportLoc, Module, -                                                     Path.back().second); -    TU->addDecl(ImportD); -    if (Consumer) -      Consumer->HandleImplicitImportDecl(ImportD); -  } -      LastModuleImportLoc = ImportLoc;    LastModuleImportResult = ModuleLoadResult(Module, false);    return LastModuleImportResult; @@ -1617,9 +1619,13 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,  void CompilerInstance::makeModuleVisible(Module *Mod,                                           Module::NameVisibilityKind Visibility, -                                         SourceLocation ImportLoc, -                                         bool Complain){ -  ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc, Complain); +                                         SourceLocation ImportLoc) { +  if (!ModuleManager) +    createModuleManager(); +  if (!ModuleManager) +    return; + +  ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc);  }  GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( | 
