diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -75,9 +75,8 @@ // the primary TU. bool ImportedByMainFile = false; - /// The compiler invocation associated with the translation unit that imports - /// this module. - std::shared_ptr Invocation; + /// Compiler invocation that can be used to build this module (without paths). + CompilerInvocation Invocation; /// Gets the canonical command line suitable for passing to clang. /// diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -19,9 +19,10 @@ using namespace dependencies; static CompilerInvocation -makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) { +makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps, + const CompilerInvocation &Invocation) { // Make a deep copy of the invocation. - CompilerInvocation CI(*Deps.Invocation); + CompilerInvocation CI(Invocation); // Remove options incompatible with explicit module build. CI.getFrontendOpts().Inputs.clear(); @@ -38,7 +39,7 @@ } static std::vector -serializeCompilerInvocation(CompilerInvocation &CI) { +serializeCompilerInvocation(const CompilerInvocation &CI) { // Set up string allocator. llvm::BumpPtrAllocator Alloc; llvm::StringSaver Strings(Alloc); @@ -55,7 +56,7 @@ std::vector ModuleDeps::getCanonicalCommandLine( std::function LookupPCMPath, std::function LookupModuleDeps) const { - CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this)); + CompilerInvocation CI(Invocation); dependencies::detail::collectPCMAndModuleMapPaths( ClangModuleDeps, LookupPCMPath, LookupModuleDeps, @@ -66,9 +67,7 @@ std::vector ModuleDeps::getCanonicalCommandLineWithoutModulePaths() const { - CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this)); - - return serializeCompilerInvocation(CI); + return serializeCompilerInvocation(Invocation); } void dependencies::detail::collectPCMAndModuleMapPaths( @@ -190,11 +189,9 @@ MD.FileDeps.insert(IF.getFile()->getName()); }); - // FIXME: Prepare the CompilerInvocation for building this module **now**, so - // that we store the actual context hash for this module (not just the - // context hash inherited from the original TU). - MD.Invocation = Instance.getInvocationPtr(); - MD.ID.ContextHash = MD.Invocation->getModuleHash(); + MD.Invocation = + makeInvocationForModuleBuildWithoutPaths(MD, Instance.getInvocation()); + MD.ID.ContextHash = MD.Invocation.getModuleHash(); llvm::DenseSet AddedModules; addAllSubmoduleDeps(M, MD, AddedModules);