From 2335d05289f7413b8aa38e962c5fddcaf7e57752 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Fri, 19 Dec 2025 15:20:59 -0800 Subject: [PATCH 1/2] [clang][modules] print mtime of input files when recorded in "module-file-info" When debugging issues related to invalidation for implicit module compilations, it can be helpful to consult the pcm what the saved mtime was. --- clang/include/clang/Serialization/ASTReader.h | 2 +- .../DependencyScannerImpl.cpp | 2 +- clang/lib/Frontend/FrontendActions.cpp | 5 +++- clang/lib/Serialization/ASTReader.cpp | 2 ++ clang/test/Modules/module-file-info-mtime.m | 24 +++++++++++++++++++ clang/test/Modules/module_file_info.m | 18 +++++++------- 6 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 clang/test/Modules/module-file-info-mtime.m diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index d276f0d21b958..d0f7de873c178 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -254,7 +254,7 @@ class ASTReaderListener { /// \returns true to continue receiving the next input file, false to stop. virtual bool visitInputFileAsRequested(StringRef FilenameAsRequested, StringRef Filename, bool isSystem, - bool isOverridden, + bool isOverridden, time_t StoredTime, bool isExplicitModule) { return true; } diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp index 201230d7d6a8e..6fdccb65c1626 100644 --- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp +++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp @@ -111,7 +111,7 @@ class PrebuiltModuleListener : public ASTReaderListener { /// considered stable. bool visitInputFileAsRequested(StringRef FilenameAsRequested, StringRef Filename, bool isSystem, - bool isOverridden, + bool isOverridden, time_t StoredTime, bool isExplicitModule) override { if (StableDirs.empty()) return false; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index e0c1d304e8290..f03b14058db40 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -798,7 +798,7 @@ namespace { /// \returns true to continue receiving the next input file, false to stop. bool visitInputFileAsRequested(StringRef FilenameAsRequested, StringRef Filename, bool isSystem, - bool isOverridden, + bool isOverridden, time_t StoredTime, bool isExplicitModule) override { Out.indent(2) << "Input file: " << FilenameAsRequested; @@ -823,6 +823,9 @@ namespace { Out << "\n"; + if (StoredTime > 0) + Out.indent(4) << "MTime: " << llvm::itostr(StoredTime) << "\n"; + return true; } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index aec61322fb8be..f8067005a2752 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5980,6 +5980,7 @@ bool ASTReader::readASTFileControlBlock( case INPUT_FILE_HASH: break; case INPUT_FILE: + time_t StoredTime = static_cast(Record[2]); bool Overridden = static_cast(Record[3]); auto [UnresolvedFilenameAsRequested, UnresolvedFilename] = getUnresolvedInputFilenames(Record, Blob); @@ -5995,6 +5996,7 @@ bool ASTReader::readASTFileControlBlock( } shouldContinue = Listener.visitInputFileAsRequested( *FilenameAsRequestedBuf, Filename, isSystemFile, Overridden, + StoredTime, /*IsExplicitModule=*/false); break; } diff --git a/clang/test/Modules/module-file-info-mtime.m b/clang/test/Modules/module-file-info-mtime.m new file mode 100644 index 0000000000000..c577207ef4287 --- /dev/null +++ b/clang/test/Modules/module-file-info-mtime.m @@ -0,0 +1,24 @@ +// Hardcode the mtime for a input file & check that is emitted in pcm during a implicit module invocation. + +// RUN: rm -fr %t +// RUN: split-file %s %t +// RUN: touch -m -a -t 202508011501 %t/BuildDir/A/A.h +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash -fimplicit-module-maps %t/client.m -fsyntax-only -I%t/BuildDir +// RUN: %clang_cc1 -module-file-info %t/cache/A.pcm | FileCheck %s + +// CHECK: Module name: A +// CHECK: Module map file: {{.*}}module.modulemap +// CHECK: Input file: {{.*}}A.h +// CHECK-NEXT: MTime: 1754085660 + + +//--- BuildDir/A/module.modulemap +module A [system] { + umbrella "." +} + +//--- BuildDir/A/A.h +typedef int local_t; + +//--- client.m +#import diff --git a/clang/test/Modules/module_file_info.m b/clang/test/Modules/module_file_info.m index f5ba25d54b97c..2aa6c3feb3c6b 100644 --- a/clang/test/Modules/module_file_info.m +++ b/clang/test/Modules/module_file_info.m @@ -48,15 +48,15 @@ // MACROS-NEXT: -DBLARG // MACROS-NEXT: -DWIBBLE=WOBBLE // CHECK: Input file: {{.*}}module.modulemap -// CHECK-NEXT: Input file: {{.*}}module.private.modulemap -// CHECK-NEXT: Input file: {{.*}}DependsOnModule.h -// CHECK-NEXT: Input file: {{.*}}module.modulemap -// CHECK-NEXT: Input file: {{.*}}other.h -// CHECK-NEXT: Input file: {{.*}}not_cxx.h -// CHECK-NEXT: Input file: {{.*}}not_coroutines.h -// CHECK-NEXT: Input file: {{.*}}SubFramework.h -// CHECK-NEXT: Input file: {{.*}}Other.h -// CHECK-NEXT: Input file: {{.*}}DependsOnModulePrivate.h +// CHECK: Input file: {{.*}}module.private.modulemap +// CHECK: Input file: {{.*}}DependsOnModule.h +// CHECK: Input file: {{.*}}module.modulemap +// CHECK: Input file: {{.*}}other.h +// CHECK: Input file: {{.*}}not_cxx.h +// CHECK: Input file: {{.*}}not_coroutines.h +// CHECK: Input file: {{.*}}SubFramework.h +// CHECK: Input file: {{.*}}Other.h +// CHECK: Input file: {{.*}}DependsOnModulePrivate.h // CHECK: Diagnostic options: // CHECK: IgnoreWarnings: Yes From 193d4714e75575944dc482f5d0cbfc317ef7c5e0 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Fri, 19 Dec 2025 16:05:17 -0800 Subject: [PATCH 2/2] Address review comments --- clang/lib/Serialization/ASTReader.cpp | 3 +-- clang/test/Modules/module-file-info-mtime.m | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index f8067005a2752..8152bd7e75dce 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5996,8 +5996,7 @@ bool ASTReader::readASTFileControlBlock( } shouldContinue = Listener.visitInputFileAsRequested( *FilenameAsRequestedBuf, Filename, isSystemFile, Overridden, - StoredTime, - /*IsExplicitModule=*/false); + StoredTime, /*IsExplicitModule=*/false); break; } if (!shouldContinue) diff --git a/clang/test/Modules/module-file-info-mtime.m b/clang/test/Modules/module-file-info-mtime.m index c577207ef4287..5a7e6fabfc6a3 100644 --- a/clang/test/Modules/module-file-info-mtime.m +++ b/clang/test/Modules/module-file-info-mtime.m @@ -1,15 +1,14 @@ -// Hardcode the mtime for a input file & check that is emitted in pcm during a implicit module invocation. +// Check that mtime from a input file of a pcm is emitted, when it was built from an implicit module invocation. // RUN: rm -fr %t // RUN: split-file %s %t -// RUN: touch -m -a -t 202508011501 %t/BuildDir/A/A.h // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash -fimplicit-module-maps %t/client.m -fsyntax-only -I%t/BuildDir // RUN: %clang_cc1 -module-file-info %t/cache/A.pcm | FileCheck %s // CHECK: Module name: A // CHECK: Module map file: {{.*}}module.modulemap // CHECK: Input file: {{.*}}A.h -// CHECK-NEXT: MTime: 1754085660 +// CHECK-NEXT: MTime: {{[0-9]+}} //--- BuildDir/A/module.modulemap