[clang] 572b89a - NFCI: [clang][deps] Simplify handling of main TU context hash (#141966)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 29 13:52:00 PDT 2025
Author: Jan Svoboda
Date: 2025-05-29T13:51:57-07:00
New Revision: 572b89a1f42b83a0cb91534295ae7f360dff6d68
URL: https://github.com/llvm/llvm-project/commit/572b89a1f42b83a0cb91534295ae7f360dff6d68
DIFF: https://github.com/llvm/llvm-project/commit/572b89a1f42b83a0cb91534295ae7f360dff6d68.diff
LOG: NFCI: [clang][deps] Simplify handling of main TU context hash (#141966)
Instead of handling the context hash in a preprocessor callback on each
file change, do it once at the end of the scan.
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 d2d0d56e5212c..e96c49883d3c6 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -311,8 +311,6 @@ class ModuleDepCollector final : public DependencyCollector {
const ArrayRef<StringRef> StableDirs;
/// Path to the main source file.
std::string MainFile;
- /// Hash identifying the compilation conditions of the current TU.
- std::string ContextHash;
/// Non-modular file dependencies. This includes the main source file and
/// textually included header files.
std::vector<std::string> FileDeps;
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index eb674246e2d51..774bfd725d0a5 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -629,13 +629,6 @@ void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
if (Reason != LexedFileChangeReason::EnterFile)
return;
- // This has to be delayed as the context hash can change at the start of
- // `CompilerInstance::ExecuteAction`.
- if (MDC.ContextHash.empty()) {
- MDC.ContextHash = MDC.ScanInstance.getInvocation().getModuleHash();
- MDC.Consumer.handleContextHash(MDC.ContextHash);
- }
-
SourceManager &SM = MDC.ScanInstance.getSourceManager();
// Dependency generation really does want to go all the way to the
@@ -717,6 +710,9 @@ void ModuleDepCollectorPP::EndOfMainFile() {
for (const Module *M : MDC.DirectModularDeps)
handleTopLevelModule(M);
+ MDC.Consumer.handleContextHash(
+ MDC.ScanInstance.getInvocation().getModuleHash());
+
MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
if (MDC.Service.getFormat() == ScanningOutputFormat::P1689)
More information about the cfe-commits
mailing list