[clang] NFCI: [clang][deps] Simplify handling of main TU context hash (PR #141966)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 29 08:37:01 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Jan Svoboda (jansvoboda11)
<details>
<summary>Changes</summary>
Instead of handling the context hash in a preprocessor callback on each file change, do it once at the end of the scan.
---
Full diff: https://github.com/llvm/llvm-project/pull/141966.diff
2 Files Affected:
- (modified) clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h (-2)
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+3-7)
``````````diff
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 06717a64c9a78..ad452a3faa73c 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -325,8 +325,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 45901cbcedcb7..a6693e5a870e2 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -632,13 +632,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
@@ -720,6 +713,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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/141966
More information about the cfe-commits
mailing list