diff --git a/clang/include/clang/Lex/PreprocessorOptions.h b/clang/include/clang/Lex/PreprocessorOptions.h --- a/clang/include/clang/Lex/PreprocessorOptions.h +++ b/clang/include/clang/Lex/PreprocessorOptions.h @@ -69,6 +69,9 @@ std::vector Includes; std::vector MacroIncludes; + /// Perform extra checks for relocatable modules when loading PCM files. + bool RelocatableModules = true; + /// Initialize the preprocessor with the compiler and target specific /// predefines. bool UsePredefines = true; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2972,6 +2972,9 @@ BaseDirectoryAsWritten = Blob; assert(!F.ModuleName.empty() && "MODULE_DIRECTORY found before MODULE_NAME"); + F.BaseDirectory = std::string(Blob); + if (!PP.getPreprocessorOpts().RelocatableModules) + break; // If we've already loaded a module map file covering this module, we may // have a better path for it (relative to the current build). Module *M = PP.getHeaderSearchInfo().lookupModule( @@ -2993,8 +2996,6 @@ } } F.BaseDirectory = std::string(M->Directory->getName()); - } else { - F.BaseDirectory = std::string(Blob); } break; } @@ -3992,7 +3993,8 @@ // usable header search context. assert(!F.ModuleName.empty() && "MODULE_NAME should come before MODULE_MAP_FILE"); - if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { + if (PP.getPreprocessorOpts().RelocatableModules && + F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { // An implicitly-loaded module file should have its module listed in some // module map file that we've already loaded. Module *M = diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -253,6 +253,9 @@ // context hashing. ScanInstance.getHeaderSearchOpts().ModulesStrictContextHash = true; + // Avoid some checks and module map parsing when loading PCM files. + ScanInstance.getPreprocessorOpts().RelocatableModules = false; + std::unique_ptr Action; if (ModuleName)