[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
This commit is contained in:
Jan Svoboda 2021-05-17 09:16:25 +02:00
parent b9d5b0c201
commit d3fb4b9065
2 changed files with 11 additions and 15 deletions

View File

@ -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.
///

View File

@ -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);