21 #include "clang/Config/config.h"
40 #include "llvm/ADT/ScopeExit.h"
41 #include "llvm/ADT/Statistic.h"
42 #include "llvm/Support/BuryPointer.h"
43 #include "llvm/Support/CrashRecoveryContext.h"
44 #include "llvm/Support/Errc.h"
45 #include "llvm/Support/FileSystem.h"
46 #include "llvm/Support/Host.h"
47 #include "llvm/Support/LockFileManager.h"
48 #include "llvm/Support/MemoryBuffer.h"
49 #include "llvm/Support/Path.h"
50 #include "llvm/Support/Program.h"
51 #include "llvm/Support/Signals.h"
52 #include "llvm/Support/TimeProfiler.h"
53 #include "llvm/Support/Timer.h"
54 #include "llvm/Support/raw_ostream.h"
58 using namespace clang;
60 CompilerInstance::CompilerInstance(
61 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
65 ModuleCache(SharedModuleCache ? SharedModuleCache
67 ThePCHContainerOperations(
std::move(PCHContainerOps)) {}
70 assert(OutputFiles.empty() &&
"Still output files in flight?");
74 std::shared_ptr<CompilerInvocation>
Value) {
75 Invocation = std::move(
Value);
79 return (BuildGlobalModuleIndex ||
80 (TheASTReader && TheASTReader->isGlobalIndexUnavailable() &&
82 !DisableGeneratingGlobalModuleIndex;
90 OwnedVerboseOutputStream.reset();
91 VerboseOutputStream = &
Value;
95 OwnedVerboseOutputStream.swap(
Value);
96 VerboseOutputStream = OwnedVerboseOutputStream.get();
115 auto TO = std::make_shared<TargetOptions>();
127 llvm::RoundingMode::NearestTiesToEven) {
129 getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
171 PP = std::move(
Value);
177 if (Context && Consumer)
186 Consumer = std::move(
Value);
188 if (Context && Consumer)
193 CompletionConsumer.reset(
Value);
197 return std::move(TheSema);
204 assert(ModuleCache.get() == &Reader->getModuleManager().getModuleCache() &&
205 "Expected ASTReader to use the same PCM cache");
206 TheASTReader = std::move(Reader);
209 std::shared_ptr<ModuleDependencyCollector>
211 return ModuleDepCollector;
215 std::shared_ptr<ModuleDependencyCollector> Collector) {
216 ModuleDepCollector = std::move(Collector);
220 std::shared_ptr<ModuleDependencyCollector> MDC) {
223 for (
auto &Name : HeaderMapFileNames)
228 std::shared_ptr<ModuleDependencyCollector> MDC) {
237 MDC->addFile(PCHInclude);
243 llvm::sys::path::native(PCHDir->getName(), DirNative);
246 for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
247 Dir != DirEnd && !EC; Dir.increment(EC)) {
255 MDC->addFile(Dir->path());
260 std::shared_ptr<ModuleDependencyCollector> MDC) {
267 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
268 llvm::MemoryBuffer::getFile(VFSFile);
271 llvm::vfs::collectVFSFromYAML(std::move(Buffer.get()),
272 nullptr, VFSFile, VFSEntries);
275 for (
auto &E : VFSEntries)
276 MDC->addFile(E.VPath, E.RPath);
284 std::unique_ptr<raw_ostream> StreamOwner;
285 raw_ostream *OS = &llvm::errs();
288 auto FileOS = std::make_unique<llvm::raw_fd_ostream>(
290 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF);
292 Diags.
Report(diag::warn_fe_cc_log_diagnostics_failure)
295 FileOS->SetUnbuffered();
297 StreamOwner = std::move(FileOS);
302 auto Logger = std::make_unique<LogDiagnosticPrinter>(*OS, DiagOpts,
303 std::move(StreamOwner));
317 StringRef OutputFile) {
318 auto SerializedConsumer =
323 Diags.
takeClient(), std::move(SerializedConsumer)));
326 Diags.
getClient(), std::move(SerializedConsumer)));
331 bool ShouldOwnClient) {
339 bool ShouldOwnClient,
348 Diags->setClient(Client, ShouldOwnClient);
353 if (Opts->VerifyDiagnostics)
375 VFS = FileMgr ? &FileMgr->getVirtualFileSystem()
378 assert(VFS &&
"FileManager has no VFS?");
380 return FileMgr.get();
401 Diags.
Report(diag::err_fe_remap_missing_from_file) << RB.first;
415 FromFile, std::unique_ptr<llvm::MemoryBuffer>(
416 const_cast<llvm::MemoryBuffer *
>(RB.second)));
422 auto ToFile = FileMgr.
getFile(RF.second);
424 Diags.
Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second;
432 Diags.
Report(diag::err_fe_remap_missing_from_file) << RF.first;
451 TheASTReader.reset();
457 PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOptsPtr(),
466 PP->createPreprocessingRecord();
470 PP->getFileManager(), PPOpts);
479 const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple();
480 if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA &&
481 PP->getAuxTargetInfo())
482 HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple();
485 PP->getLangOpts(), *HeaderSearchTriple);
489 if (PP->getLangOpts().Modules && PP->getLangOpts().ImplicitModules) {
491 PP->getHeaderSearchInfo().setModuleHash(ModuleHash);
492 PP->getHeaderSearchInfo().setModuleCachePath(
507 ModuleDepCollector = std::make_shared<ModuleDependencyCollector>(
513 if (ModuleDepCollector) {
520 for (
auto &Listener : DependencyCollectors)
521 Listener->attachToPreprocessor(*PP);
528 if (OutputPath ==
"-")
546 llvm::sys::path::append(SpecificModuleCache, ModuleHash);
573 void ReadModuleName(StringRef ModuleName)
override {
576 LoadedModules.push_back(ModuleName.str());
581 for (
const std::string &LoadedModule : LoadedModules)
584 LoadedModules.clear();
587 void markAllUnavailable() {
588 for (
const std::string &LoadedModule : LoadedModules) {
591 M->HasIncompatibleModuleFile =
true;
597 while (!Stack.empty()) {
598 Module *Current = Stack.pop_back_val();
599 if (Current->IsUnimportable)
continue;
600 Current->IsAvailable =
true;
601 Stack.insert(Stack.end(),
602 Current->submodule_begin(), Current->submodule_end());
606 LoadedModules.clear();
613 bool AllowPCHWithCompilerErrors,
void *DeserializationListener,
614 bool OwnDeserializationListener) {
621 DeserializationListener, OwnDeserializationListener,
Preamble,
626 StringRef Path, StringRef Sysroot,
631 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
632 ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
633 void *DeserializationListener,
bool OwnDeserializationListener,
634 bool Preamble,
bool UseGlobalModuleIndex) {
638 PP, ModuleCache, &Context, PCHContainerRdr, Extensions,
639 Sysroot.empty() ?
"" : Sysroot.data(), DisableValidation,
640 AllowPCHWithCompilerErrors,
false,
642 UseGlobalModuleIndex));
648 Reader->setDeserializationListener(
650 OwnDeserializationListener);
652 for (
auto &Listener : DependencyCollectors)
653 Listener->attachToASTReader(*Reader);
655 auto Listener = std::make_unique<ReadModuleNames>(PP);
656 auto &ListenerRef = *Listener;
658 std::move(Listener));
660 switch (Reader->ReadAST(Path,
669 ListenerRef.registerAll();
685 ListenerRef.markAllUnavailable();
712 if (!CompletionConsumer) {
718 if (!CompletionConsumer)
728 FrontendTimerGroup.reset(
729 new llvm::TimerGroup(
"frontend",
"Clang front-end time report"));
731 new llvm::Timer(
"frontend",
"Clang front-end timer",
732 *FrontendTimerGroup));
752 TUKind, CompletionConsumer));
754 if (ExternalSemaSrc) {
755 TheSema->addExternalSource(ExternalSemaSrc.get());
756 ExternalSemaSrc->InitializeSema(*TheSema);
764 for (OutputFile &OF : OutputFiles) {
767 consumeError(OF.File->discard());
768 if (!OF.Filename.empty())
776 if (OF.File->TmpName.empty()) {
777 consumeError(OF.File->discard());
784 FileMgr->FixupRelativePath(NewOutFile);
786 llvm::Error E = OF.File->keep(NewOutFile);
791 << OF.File->TmpName << OF.Filename << std::move(E);
796 if (DeleteBuiltModules) {
797 for (
auto &
Module : BuiltModules)
799 BuiltModules.clear();
804 bool Binary, StringRef InFile, StringRef Extension,
bool RemoveFileOnSignal,
805 bool CreateMissingDirectories,
bool ForceUseTemporary) {
808 if (OutputPath.empty()) {
809 if (InFile ==
"-" || Extension.empty()) {
812 PathStorage.emplace(InFile);
813 llvm::sys::path::replace_extension(*PathStorage, Extension);
814 OutputPath = *PathStorage;
820 CreateMissingDirectories);
824 return std::make_unique<llvm::raw_null_ostream>();
827 std::unique_ptr<raw_pwrite_stream>
829 bool RemoveFileOnSignal,
bool UseTemporary,
830 bool CreateMissingDirectories) {
832 createOutputFileImpl(OutputPath, Binary, RemoveFileOnSignal, UseTemporary,
833 CreateMissingDirectories);
835 return std::move(*OS);
837 << OutputPath << errorToErrorCode(OS.takeError()).message();
842 CompilerInstance::createOutputFileImpl(StringRef OutputPath,
bool Binary,
843 bool RemoveFileOnSignal,
845 bool CreateMissingDirectories) {
846 assert((!CreateMissingDirectories || UseTemporary) &&
847 "CreateMissingDirectories is only allowed when using temporary files");
849 std::unique_ptr<llvm::raw_fd_ostream> OS;
853 if (OutputPath ==
"-")
854 UseTemporary =
false;
856 llvm::sys::fs::file_status Status;
857 llvm::sys::fs::status(OutputPath, Status);
858 if (llvm::sys::fs::exists(Status)) {
860 if (!llvm::sys::fs::can_write(OutputPath))
861 return llvm::errorCodeToError(
866 if (!llvm::sys::fs::is_regular_file(Status))
867 UseTemporary =
false;
878 StringRef OutputExtension = llvm::sys::path::extension(OutputPath);
880 StringRef(OutputPath).drop_back(OutputExtension.size());
881 TempPath +=
"-%%%%%%%%";
882 TempPath += OutputExtension;
886 TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
887 Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
889 llvm::Error E = handleErrors(
890 ExpectedFile.takeError(), [&](
const llvm::ECError &E) -> llvm::Error {
891 std::error_code EC = E.convertToErrorCode();
892 if (CreateMissingDirectories &&
893 EC == llvm::errc::no_such_file_or_directory) {
894 StringRef Parent = llvm::sys::path::parent_path(OutputPath);
895 EC = llvm::sys::fs::create_directories(Parent);
897 ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
899 return llvm::errorCodeToError(
900 llvm::errc::no_such_file_or_directory);
903 return llvm::errorCodeToError(EC);
907 consumeError(std::move(E));
909 Temp = std::move(ExpectedFile.get());
910 OS.reset(
new llvm::raw_fd_ostream(Temp->FD,
false));
911 OSFile = Temp->TmpName;
921 OS.reset(
new llvm::raw_fd_ostream(
923 (Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_TextWithCRLF)));
925 return llvm::errorCodeToError(EC);
930 OutputFiles.emplace_back(((OutputPath !=
"-") ? OutputPath :
"").str(),
933 if (!Binary ||
OS->supportsSeeking())
934 return std::move(OS);
936 return std::make_unique<llvm::buffer_unique_ostream>(std::move(OS));
960 "Couldn't establish MainFileID!");
964 StringRef InputFile = Input.
getFile();
967 auto FileOrErr = InputFile ==
"-"
972 auto EC = llvm::errorToErrorCode(FileOrErr.takeError());
973 if (InputFile !=
"-")
974 Diags.
Report(diag::err_fe_error_reading) << InputFile;
976 Diags.
Report(diag::err_fe_error_reading_stdin) << EC.message();
984 "Couldn't establish MainFileID!");
991 assert(
hasDiagnostics() &&
"Diagnostics engine is not initialized!");
993 assert(!
getFrontendOpts().ShowVersion &&
"Client must handle '-version'!");
1000 auto FinishDiagnosticClient = llvm::make_scope_exit([&]() {
1019 OS <<
"clang -cc1 version " CLANG_VERSION_STRING
1020 <<
" based upon " << BACKEND_PACKAGE_STRING
1021 <<
" default target " << llvm::sys::getDefaultTargetTriple() <<
"\n";
1027 llvm::EnableStatistics(
false);
1036 if (llvm::Error Err = Act.
Execute()) {
1037 consumeError(std::move(Err));
1050 OS << NumWarnings <<
" warning" << (NumWarnings == 1 ?
"" :
"s");
1051 if (NumWarnings && NumErrors)
1054 OS << NumErrors <<
" error" << (NumErrors == 1 ?
"" :
"s");
1055 if (NumWarnings || NumErrors) {
1059 OS <<
" when compiling for host";
1073 llvm::PrintStatistics(OS);
1076 if (!StatsFile.empty()) {
1078 auto StatS = std::make_unique<llvm::raw_fd_ostream>(
1079 StatsFile, EC, llvm::sys::fs::OF_TextWithCRLF);
1082 << StatsFile << EC.message();
1084 llvm::PrintStatisticsJSON(*StatS);
1095 if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &
Error))
1101 for (
const FrontendPluginRegistry::entry &Plugin :
1102 FrontendPluginRegistry::entries()) {
1103 std::unique_ptr<PluginASTAction>
P(Plugin.instantiate());
1115 if (LangOpts.OpenCL)
1130 StringRef OriginalModuleMapFile, StringRef ModuleFileName,
1135 llvm::TimeTraceScope TimeScope(
"Module Compile", ModuleName);
1141 ImportLoc, diag::err_module_rebuild_finalized)
1148 std::make_shared<CompilerInvocation>(ImportingInstance.
getInvocation());
1160 llvm::erase_if(PPOpts.
Macros,
1161 [&HSOpts](
const std::pair<std::string, bool> &def) {
1162 StringRef MacroDef = def.first;
1163 return HSOpts.ModulesIgnoreMacros.contains(
1164 llvm::CachedHashString(MacroDef.split(
'=').first));
1168 Invocation->getLangOpts()->ModuleName =
1172 Invocation->getLangOpts()->CurrentModule =
std::string(ModuleName);
1181 std::make_shared<PreprocessorOptions::FailedModulesSet>();
1188 FrontendOpts.
OutputFile = ModuleFileName.str();
1195 FrontendOpts.
Inputs = {Input};
1200 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
1202 Invocation->getModuleHash() &&
"Module hash mismatch!");
1210 auto &Inv = *Invocation;
1211 Instance.setInvocation(std::move(Invocation));
1220 Instance.createSourceManager(Instance.getFileManager());
1234 diag::remark_module_build)
1235 << ModuleName << ModuleFileName;
1237 PreBuildStep(Instance);
1241 llvm::CrashRecoveryContext CRC;
1242 CRC.RunSafelyOnThread(
1245 Instance.ExecuteAction(Action);
1249 PostBuildStep(Instance);
1252 diag::remark_module_build_done)
1257 Instance.clearOutputFiles(
true);
1261 return !Instance.getDiagnostics().hasErrorOccurred() ||
1262 Instance.getFrontendOpts().AllowPCMWithCompilerErrors;
1267 StringRef
Filename = llvm::sys::path::filename(
File->getName());
1269 if (
Filename ==
"module_private.map")
1270 llvm::sys::path::append(PublicFilename,
"module.map");
1271 else if (
Filename ==
"module.private.modulemap")
1272 llvm::sys::path::append(PublicFilename,
"module.modulemap");
1275 if (
auto FE = FileMgr.
getFile(PublicFilename))
1285 StringRef ModuleFileName) {
1300 ModuleMapFile = PublicMMFile;
1314 llvm::sys::path::append(FakeModuleMapFile,
"__inferred_module.map");
1317 llvm::raw_string_ostream OS(InferredModuleMapContent);
1327 std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =
1328 llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent);
1329 ModuleMapFile = Instance.getFileManager().getVirtualFile(
1330 FakeModuleMapFile, InferredModuleMapContent.size(), 0);
1331 Instance.getSourceManager().overrideFileContents(
1332 ModuleMapFile, std::move(ModuleMapBuffer));
1361 ModuleLoadCapabilities);
1373 Diags.
Report(ModuleNameLoc, diag::err_module_not_built)
1385 StringRef ModuleFileName) {
1389 diag::err_module_not_built)
1412 Diags.
Report(ModuleNameLoc, diag::remark_module_lock)
1417 StringRef Dir = llvm::sys::path::parent_path(ModuleFileName);
1418 llvm::sys::fs::create_directories(Dir);
1421 llvm::LockFileManager Locked(ModuleFileName);
1423 case llvm::LockFileManager::LFS_Error:
1427 Diags.
Report(ModuleNameLoc, diag::remark_module_lock_failure)
1430 Locked.unsafeRemoveLockFile();
1432 case llvm::LockFileManager::LFS_Owned:
1435 ModuleNameLoc,
Module, ModuleFileName);
1437 case llvm::LockFileManager::LFS_Shared:
1443 switch (Locked.waitForUnlock()) {
1444 case llvm::LockFileManager::Res_Success:
1446 case llvm::LockFileManager::Res_OwnerDied:
1448 case llvm::LockFileManager::Res_Timeout:
1452 Diags.
Report(ModuleNameLoc, diag::remark_module_lock_timeout)
1455 Locked.unsafeRemoveLockFile();
1460 bool OutOfDate =
false;
1462 Module, ModuleFileName, &OutOfDate))
1501 if (!
Id->hadMacroDefinition())
1507 for (
auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) {
1512 if (
auto *DMD = dyn_cast<DefMacroDirective>(MD))
1513 CmdLineDefinition = DMD->getMacroInfo();
1518 if (CurrentDefinition == CmdLineDefinition) {
1520 }
else if (!CurrentDefinition) {
1523 PP.
Diag(ImportLoc, diag::warn_module_config_macro_undef)
1525 auto LatestDef = LatestLocalMD->getDefinition();
1526 assert(LatestDef.isUndefined() &&
1527 "predefined macro went away with no #undef?");
1528 PP.
Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here)
1531 }
else if (!CmdLineDefinition) {
1534 PP.
Diag(ImportLoc, diag::warn_module_config_macro_undef)
1536 PP.
Diag(CurrentDefinition->getDefinitionLoc(),
1537 diag::note_module_def_undef_here)
1539 }
else if (!CurrentDefinition->isIdenticalTo(*CmdLineDefinition, PP,
1542 PP.
Diag(ImportLoc, diag::warn_module_config_macro_undef)
1544 PP.
Diag(CurrentDefinition->getDefinitionLoc(),
1545 diag::note_module_def_undef_here)
1553 llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::OF_None);
1559 llvm::sys::fs::file_status StatBuf;
1562 assert(!TimestampFile.empty());
1563 llvm::sys::path::append(TimestampFile,
"modules.timestamp");
1566 if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {
1568 if (EC == std::errc::no_such_file_or_directory) {
1576 time_t TimeStampModTime =
1577 llvm::sys::toTimeT(StatBuf.getLastModificationTime());
1578 time_t CurrentTime = time(
nullptr);
1591 llvm::sys::path::native(HSOpts.
ModuleCachePath, ModuleCachePathNative);
1592 for (llvm::sys::fs::directory_iterator Dir(ModuleCachePathNative, EC), DirEnd;
1593 Dir != DirEnd && !EC; Dir.increment(EC)) {
1595 if (!llvm::sys::fs::is_directory(Dir->path()))
1599 for (llvm::sys::fs::directory_iterator
File(Dir->path(), EC), FileEnd;
1600 File != FileEnd && !EC;
File.increment(EC)) {
1602 StringRef Extension = llvm::sys::path::extension(
File->path());
1603 if (Extension !=
".pcm" && Extension !=
".timestamp" &&
1604 llvm::sys::path::filename(
File->path()) !=
"modules.idx")
1609 if (llvm::sys::fs::status(
File->path(), StatBuf))
1613 time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
1614 if (CurrentTime - FileAccessTime <=
1629 if (llvm::sys::fs::directory_iterator(Dir->path(), EC) ==
1630 llvm::sys::fs::directory_iterator() && !EC)
1645 !
getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty() &&
1655 std::unique_ptr<llvm::Timer> ReadTimer;
1657 if (FrontendTimerGroup)
1658 ReadTimer = std::make_unique<llvm::Timer>(
"reading_modules",
1660 *FrontendTimerGroup);
1664 Sysroot.empty() ?
"" : Sysroot.c_str(),
1671 TheASTReader->setDeserializationListener(
1678 TheASTReader->InitializeSema(
getSema());
1682 for (
auto &Listener : DependencyCollectors)
1683 Listener->attachToASTReader(*TheASTReader);
1688 if (FrontendTimerGroup)
1689 Timer.init(
"preloading." + FileName.str(),
"Preloading " + FileName.str(),
1690 *FrontendTimerGroup);
1691 llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer :
nullptr);
1699 bool ConfigMismatchIsRecoverable =
1704 auto Listener = std::make_unique<ReadModuleNames>(*PP);
1705 auto &ListenerRef = *Listener;
1707 std::move(Listener));
1710 switch (TheASTReader->ReadAST(
1716 ListenerRef.registerAll();
1725 ListenerRef.markAllUnavailable();
1737 MS_PrebuiltModulePath,
1738 MS_ModuleBuildPragma
1748 assert(ModuleFilename.empty() &&
"Already has a module source?");
1752 auto BuiltModuleIt = BuiltModules.find(ModuleName);
1753 if (BuiltModuleIt != BuiltModules.end()) {
1754 ModuleFilename = BuiltModuleIt->second;
1755 return MS_ModuleBuildPragma;
1765 if (!ModuleFilename.empty())
1766 return MS_PrebuiltModulePath;
1772 return MS_ModuleCache;
1775 return MS_ModuleNotFound;
1784 HS.
lookupModule(ModuleName, ImportLoc,
true, !IsInclusionDirective);
1788 ModuleSource Source =
1790 if (Source == MS_ModuleNotFound) {
1793 << ModuleName <<
SourceRange(ImportLoc, ModuleNameLoc);
1796 if (ModuleFilename.empty()) {
1814 if (FrontendTimerGroup)
1815 Timer.init(
"loading." + ModuleFilename,
"Loading " + ModuleFilename,
1816 *FrontendTimerGroup);
1817 llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer :
nullptr);
1818 llvm::TimeTraceScope TimeScope(
"Module Load", ModuleName);
1822 unsigned ARRFlags = Source == MS_ModuleCache
1825 : Source == MS_PrebuiltModulePath
1829 Source == MS_PrebuiltModulePath
1831 : Source == MS_ModuleBuildPragma
1834 ImportLoc, ARRFlags)) {
1838 assert(Source != MS_ModuleCache &&
1839 "missing module, but file loaded from cache");
1843 M = HS.
lookupModule(ModuleName, ImportLoc,
true, !IsInclusionDirective);
1847 if (
auto ModuleFile = FileMgr->getFile(ModuleFilename))
1862 if (Source == MS_PrebuiltModulePath)
1866 diag::warn_module_config_mismatch)
1883 if (Source != MS_ModuleCache) {
1891 assert(M &&
"missing module, but trying to compile for cache");
1895 ModuleBuildStack::iterator Pos = ModPath.begin(), PosEnd = ModPath.end();
1896 for (; Pos != PosEnd; ++Pos) {
1897 if (Pos->first == ModuleName)
1901 if (Pos != PosEnd) {
1903 for (; Pos != PosEnd; ++Pos) {
1904 CyclePath += Pos->first;
1905 CyclePath +=
" -> ";
1907 CyclePath += ModuleName;
1910 << ModuleName << CyclePath;
1919 << ModuleName <<
SourceRange(ImportLoc, ModuleNameLoc);
1927 "undiagnosed error in compileModuleAndReadAST");
1941 bool IsInclusionDirective) {
1943 StringRef ModuleName = Path[0].first->getName();
1949 if (ImportLoc.
isValid() && LastModuleImportLoc == ImportLoc) {
1951 if (LastModuleImportResult && ModuleName !=
getLangOpts().CurrentModule)
1952 TheASTReader->makeModuleVisible(LastModuleImportResult,
Visibility,
1954 return LastModuleImportResult;
1963 }
else if (ModuleName ==
getLangOpts().CurrentModule) {
1966 ModuleName, ImportLoc,
true,
1967 !IsInclusionDirective);
1979 ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective);
1980 if (!Result.isNormal())
1983 DisableGeneratingGlobalModuleIndex =
true;
1995 bool MapPrivateSubModToTopLevel =
false;
1996 for (
unsigned I = 1, N = Path.size(); I != N; ++I) {
1997 StringRef Name = Path[I].first->getName();
2004 if (!
Sub && PP->
getLangOpts().ImplicitModules && Name ==
"Private" &&
2007 PrivateModule.append(
"_Private");
2012 PrivPath.push_back(std::make_pair(&II, Path[0].second));
2015 !IsInclusionDirective))
2018 MapPrivateSubModToTopLevel =
true;
2020 diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
2022 diag::warn_no_priv_submodule_use_toplevel)
2028 diag::note_private_top_level_defined);
2040 Name.edit_distance(SubModule->Name,
2041 true, BestEditDistance);
2042 if (ED <= BestEditDistance) {
2043 if (ED < BestEditDistance) {
2045 BestEditDistance = ED;
2048 Best.push_back(SubModule->Name);
2053 if (Best.size() == 1) {
2056 <<
SourceRange(Path[0].second, Path[I - 1].second)
2069 <<
SourceRange(Path[0].second, Path[I - 1].second);
2088 <<
SourceRange(Path.front().second, Path.back().second);
2097 <<
SourceRange(Path.front().second, Path.back().second);
2098 LastModuleImportLoc = ImportLoc;
2108 for (
unsigned I = 0, N = TopModule->
ConfigMacros.size(); I != N; ++I) {
2119 LastModuleImportLoc = ImportLoc;
2121 return LastModuleImportResult;
2125 StringRef ModuleName,
2129 for (
auto &C : CleanModuleName)
2137 if (std::error_code EC = llvm::sys::fs::createTemporaryFile(
2138 CleanModuleName,
"pcm", ModuleFileName)) {
2140 << ModuleFileName << EC.message();
2143 std::string ModuleMapFileName = (CleanModuleName +
".map").str();
2155 const FileEntry *ModuleMapFile = Other.getFileManager().getVirtualFile(
2156 ModuleMapFileName, NullTerminatedSource.size(), 0);
2157 Other.getSourceManager().overrideFileContents(
2158 ModuleMapFile, llvm::MemoryBuffer::getMemBuffer(NullTerminatedSource));
2160 Other.BuiltModules = std::move(BuiltModules);
2161 Other.DeleteBuiltModules =
false;
2165 BuiltModules = std::move(Other.BuiltModules);
2170 ModuleFileName, PreBuildStep, PostBuildStep)) {
2172 llvm::sys::RemoveFileOnSignal(ModuleFileName);
2184 TheASTReader->makeModuleVisible(Mod,
Visibility, ImportLoc);
2189 if (
getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())
2198 TheASTReader->loadGlobalIndex();
2203 llvm::sys::fs::create_directories(
2212 consumeError(std::move(Err));
2215 TheASTReader->resetForReload();
2216 TheASTReader->loadGlobalIndex();
2217 GlobalIndex = TheASTReader->getGlobalIndex();
2221 if (!HaveFullGlobalModuleIndex && GlobalIndex && !
buildingModule()) {
2223 bool RecreateIndex =
false;
2226 Module *TheModule = I->second;
2230 Path.push_back(std::make_pair(
2232 std::reverse(Path.begin(), Path.end());
2235 RecreateIndex =
true;
2238 if (RecreateIndex) {
2243 consumeError(std::move(Err));
2246 TheASTReader->resetForReload();
2247 TheASTReader->loadGlobalIndex();
2248 GlobalIndex = TheASTReader->getGlobalIndex();
2250 HaveFullGlobalModuleIndex =
true;
2284 ExternalSemaSrc = std::move(ESS);