Skip to content

Commit d3fb4b9

Browse files
committed
[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
1 parent b9d5b0c commit d3fb4b9

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ struct ModuleDeps {
7575
// the primary TU.
7676
bool ImportedByMainFile = false;
7777

78-
/// The compiler invocation associated with the translation unit that imports
79-
/// this module.
80-
std::shared_ptr<CompilerInvocation> Invocation;
78+
/// Compiler invocation that can be used to build this module (without paths).
79+
CompilerInvocation Invocation;
8180

8281
/// Gets the canonical command line suitable for passing to clang.
8382
///

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ using namespace tooling;
1919
using namespace dependencies;
2020

2121
static CompilerInvocation
22-
makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
22+
makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps,
23+
const CompilerInvocation &Invocation) {
2324
// Make a deep copy of the invocation.
24-
CompilerInvocation CI(*Deps.Invocation);
25+
CompilerInvocation CI(Invocation);
2526

2627
// Remove options incompatible with explicit module build.
2728
CI.getFrontendOpts().Inputs.clear();
@@ -38,7 +39,7 @@ makeInvocationForModuleBuildWithoutPaths(const ModuleDeps &Deps) {
3839
}
3940

4041
static std::vector<std::string>
41-
serializeCompilerInvocation(CompilerInvocation &CI) {
42+
serializeCompilerInvocation(const CompilerInvocation &CI) {
4243
// Set up string allocator.
4344
llvm::BumpPtrAllocator Alloc;
4445
llvm::StringSaver Strings(Alloc);
@@ -55,7 +56,7 @@ serializeCompilerInvocation(CompilerInvocation &CI) {
5556
std::vector<std::string> ModuleDeps::getCanonicalCommandLine(
5657
std::function<StringRef(ModuleID)> LookupPCMPath,
5758
std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps) const {
58-
CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
59+
CompilerInvocation CI(Invocation);
5960

6061
dependencies::detail::collectPCMAndModuleMapPaths(
6162
ClangModuleDeps, LookupPCMPath, LookupModuleDeps,
@@ -66,9 +67,7 @@ std::vector<std::string> ModuleDeps::getCanonicalCommandLine(
6667

6768
std::vector<std::string>
6869
ModuleDeps::getCanonicalCommandLineWithoutModulePaths() const {
69-
CompilerInvocation CI(makeInvocationForModuleBuildWithoutPaths(*this));
70-
71-
return serializeCompilerInvocation(CI);
70+
return serializeCompilerInvocation(Invocation);
7271
}
7372

7473
void dependencies::detail::collectPCMAndModuleMapPaths(
@@ -190,11 +189,9 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
190189
MD.FileDeps.insert(IF.getFile()->getName());
191190
});
192191

193-
// FIXME: Prepare the CompilerInvocation for building this module **now**, so
194-
// that we store the actual context hash for this module (not just the
195-
// context hash inherited from the original TU).
196-
MD.Invocation = Instance.getInvocationPtr();
197-
MD.ID.ContextHash = MD.Invocation->getModuleHash();
192+
MD.Invocation =
193+
makeInvocationForModuleBuildWithoutPaths(MD, Instance.getInvocation());
194+
MD.ID.ContextHash = MD.Invocation.getModuleHash();
198195

199196
llvm::DenseSet<const Module *> AddedModules;
200197
addAllSubmoduleDeps(M, MD, AddedModules);

0 commit comments

Comments
 (0)