Skip to content

Commit 36c27c6

Browse files
authored
[clang][modules] print mtime of input files when recorded in "module-file-info" (#173120)
When debugging issues related to invalidation for implicit module compilations, it can be helpful to consult the PCM to see what the saved mtime was.
1 parent 1a4596c commit 36c27c6

File tree

6 files changed

+40
-13
lines changed

6 files changed

+40
-13
lines changed

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class ASTReaderListener {
254254
/// \returns true to continue receiving the next input file, false to stop.
255255
virtual bool visitInputFileAsRequested(StringRef FilenameAsRequested,
256256
StringRef Filename, bool isSystem,
257-
bool isOverridden,
257+
bool isOverridden, time_t StoredTime,
258258
bool isExplicitModule) {
259259
return true;
260260
}

clang/lib/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class PrebuiltModuleListener : public ASTReaderListener {
111111
/// considered stable.
112112
bool visitInputFileAsRequested(StringRef FilenameAsRequested,
113113
StringRef Filename, bool isSystem,
114-
bool isOverridden,
114+
bool isOverridden, time_t StoredTime,
115115
bool isExplicitModule) override {
116116
if (StableDirs.empty())
117117
return false;

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ namespace {
798798
/// \returns true to continue receiving the next input file, false to stop.
799799
bool visitInputFileAsRequested(StringRef FilenameAsRequested,
800800
StringRef Filename, bool isSystem,
801-
bool isOverridden,
801+
bool isOverridden, time_t StoredTime,
802802
bool isExplicitModule) override {
803803

804804
Out.indent(2) << "Input file: " << FilenameAsRequested;
@@ -823,6 +823,9 @@ namespace {
823823

824824
Out << "\n";
825825

826+
if (StoredTime > 0)
827+
Out.indent(4) << "MTime: " << llvm::itostr(StoredTime) << "\n";
828+
826829
return true;
827830
}
828831

clang/lib/Serialization/ASTReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6014,6 +6014,7 @@ bool ASTReader::readASTFileControlBlock(
60146014
case INPUT_FILE_HASH:
60156015
break;
60166016
case INPUT_FILE:
6017+
time_t StoredTime = static_cast<time_t>(Record[2]);
60176018
bool Overridden = static_cast<bool>(Record[3]);
60186019
auto [UnresolvedFilenameAsRequested, UnresolvedFilename] =
60196020
getUnresolvedInputFilenames(Record, Blob);
@@ -6029,7 +6030,7 @@ bool ASTReader::readASTFileControlBlock(
60296030
}
60306031
shouldContinue = Listener.visitInputFileAsRequested(
60316032
*FilenameAsRequestedBuf, Filename, isSystemFile, Overridden,
6032-
/*IsExplicitModule=*/false);
6033+
StoredTime, /*IsExplicitModule=*/false);
60336034
break;
60346035
}
60356036
if (!shouldContinue)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Check that mtime from a input file of a pcm is emitted, when it was built from an implicit module invocation.
2+
3+
// RUN: rm -fr %t
4+
// RUN: split-file %s %t
5+
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash -fimplicit-module-maps %t/client.m -fsyntax-only -I%t/BuildDir
6+
// RUN: %clang_cc1 -module-file-info %t/cache/A.pcm | FileCheck %s
7+
8+
// CHECK: Module name: A
9+
// CHECK: Module map file: {{.*}}module.modulemap
10+
// CHECK: Input file: {{.*}}A.h
11+
// CHECK-NEXT: MTime: {{[0-9]+}}
12+
13+
14+
//--- BuildDir/A/module.modulemap
15+
module A [system] {
16+
umbrella "."
17+
}
18+
19+
//--- BuildDir/A/A.h
20+
typedef int local_t;
21+
22+
//--- client.m
23+
#import <A/A.h>

clang/test/Modules/module_file_info.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
// MACROS-NEXT: -DBLARG
4949
// MACROS-NEXT: -DWIBBLE=WOBBLE
5050
// CHECK: Input file: {{.*}}module.modulemap
51-
// CHECK-NEXT: Input file: {{.*}}module.private.modulemap
52-
// CHECK-NEXT: Input file: {{.*}}DependsOnModule.h
53-
// CHECK-NEXT: Input file: {{.*}}module.modulemap
54-
// CHECK-NEXT: Input file: {{.*}}other.h
55-
// CHECK-NEXT: Input file: {{.*}}not_cxx.h
56-
// CHECK-NEXT: Input file: {{.*}}not_coroutines.h
57-
// CHECK-NEXT: Input file: {{.*}}SubFramework.h
58-
// CHECK-NEXT: Input file: {{.*}}Other.h
59-
// CHECK-NEXT: Input file: {{.*}}DependsOnModulePrivate.h
51+
// CHECK: Input file: {{.*}}module.private.modulemap
52+
// CHECK: Input file: {{.*}}DependsOnModule.h
53+
// CHECK: Input file: {{.*}}module.modulemap
54+
// CHECK: Input file: {{.*}}other.h
55+
// CHECK: Input file: {{.*}}not_cxx.h
56+
// CHECK: Input file: {{.*}}not_coroutines.h
57+
// CHECK: Input file: {{.*}}SubFramework.h
58+
// CHECK: Input file: {{.*}}Other.h
59+
// CHECK: Input file: {{.*}}DependsOnModulePrivate.h
6060

6161
// CHECK: Diagnostic options:
6262
// CHECK: IgnoreWarnings: Yes

0 commit comments

Comments
 (0)