[clang] d3fb4b9 - [clang][deps] NFC: Report modules' context hash

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon May 17 00:24:34 PDT 2021


Author: Jan Svoboda
Date: 2021-05-17T09:24:23+02:00
New Revision: d3fb4b9065e93e2617db44f3ab9c31f341d9cd1f

URL: https://github.com/llvm/llvm-project/commit/d3fb4b9065e93e2617db44f3ab9c31f341d9cd1f
DIFF: https://github.com/llvm/llvm-project/commit/d3fb4b9065e93e2617db44f3ab9c31f341d9cd1f.diff

LOG: [clang][deps] NFC: Report modules' context hash

This patch eagerly constructs and modifies CompilerInvocation of modular dependencies in order to report the correct context hash instead of the hash of the original translation unit.

No functionality change here, since we currently don't modify CompilerInvocation in a way that affects the context hash.

Depends on D102473.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D102482

Added: 
    

Modified: 
    clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
    clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 8d191278f22ab..7599a8bf45b9e 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -75,9 +75,8 @@ struct ModuleDeps {
   // the primary TU.
   bool ImportedByMainFile = false;
 
-  /// The compiler invocation associated with the translation unit that imports
-  /// this module.
-  std::shared_ptr<CompilerInvocation> 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
index 517312aec8954..51b7fc48628c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -19,9 +19,10 @@ using namespace tooling;
 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 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
 }
 
 static std::vector<std::string>
-serializeCompilerInvocation(CompilerInvocation &CI) {
+serializeCompilerInvocation(const CompilerInvocation &CI) {
   // Set up string allocator.
   llvm::BumpPtrAllocator Alloc;
   llvm::StringSaver Strings(Alloc);
@@ -55,7 +56,7 @@ serializeCompilerInvocation(CompilerInvocation &CI) {
 std::vector<std::string> ModuleDeps::getCanonicalCommandLine(
     std::function<StringRef(ModuleID)> LookupPCMPath,
     std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps) const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
+  CompilerInvocation CI(Invocation);
 
   dependencies::detail::collectPCMAndModuleMapPaths(
       ClangModuleDeps, LookupPCMPath, LookupModuleDeps,
@@ -66,9 +67,7 @@ std::vector<std::string> ModuleDeps::getCanonicalCommandLine(
 
 std::vector<std::string>
 ModuleDeps::getCanonicalCommandLineWithoutModulePaths() const {
-  CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
-
-  return serializeCompilerInvocation(CI);
+  return serializeCompilerInvocation(Invocation);
 }
 
 void dependencies::detail::collectPCMAndModuleMapPaths(
@@ -190,11 +189,9 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
         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<const Module *> AddedModules;
   addAllSubmoduleDeps(M, MD, AddedModules);


        


More information about the cfe-commits mailing list