Skip to content

Commit 572b89a

Browse files
authored
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.
1 parent 17ee4ae commit 572b89a

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ class ModuleDepCollector final : public DependencyCollector {
311311
const ArrayRef<StringRef> StableDirs;
312312
/// Path to the main source file.
313313
std::string MainFile;
314-
/// Hash identifying the compilation conditions of the current TU.
315-
std::string ContextHash;
316314
/// Non-modular file dependencies. This includes the main source file and
317315
/// textually included header files.
318316
std::vector<std::string> FileDeps;

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,6 @@ void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
629629
if (Reason != LexedFileChangeReason::EnterFile)
630630
return;
631631

632-
// This has to be delayed as the context hash can change at the start of
633-
// `CompilerInstance::ExecuteAction`.
634-
if (MDC.ContextHash.empty()) {
635-
MDC.ContextHash = MDC.ScanInstance.getInvocation().getModuleHash();
636-
MDC.Consumer.handleContextHash(MDC.ContextHash);
637-
}
638-
639632
SourceManager &SM = MDC.ScanInstance.getSourceManager();
640633

641634
// Dependency generation really does want to go all the way to the
@@ -717,6 +710,9 @@ void ModuleDepCollectorPP::EndOfMainFile() {
717710
for (const Module *M : MDC.DirectModularDeps)
718711
handleTopLevelModule(M);
719712

713+
MDC.Consumer.handleContextHash(
714+
MDC.ScanInstance.getInvocation().getModuleHash());
715+
720716
MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
721717

722718
if (MDC.Service.getFormat() == ScanningOutputFormat::P1689)

0 commit comments

Comments
 (0)