Skip to content

Commit 9a9cff1

Browse files
authored
[Modules] Process include files changes (#90319)
There were two diffs that introduced some options useful when you build modules externally and cannot rely on file modification time as the key for detecting input file changes: - [D67249](https://reviews.llvm.org/D67249) introduced the `-fmodules-validate-input-files-content` option, which allows the use of file content hash in addition to the modification time. - [D141632](https://reviews.llvm.org/D141632) propagated the use of `-fno-pch-timestamps` with Clang modules. There is a problem when the size of the input file (header) is not modified but the content is. In this case, Clang cannot detect the file change when the `-fno-pch-timestamps` option is used. The `-fmodules-validate-input-files-content` option should help, but there is an issue with its application: it's not applied when the modification time is stored as zero that is the case for `-fno-pch-timestamps`. The issue can be fixed using the same trick that was applied during the processing of `ForceCheckCXX20ModulesInputFiles`: ``` // When ForceCheckCXX20ModulesInputFiles and ValidateASTInputFilesContent // enabled, it is better to check the contents of the inputs. Since we can't // get correct modified time information for inputs from overriden inputs. if (HSOpts.ForceCheckCXX20ModulesInputFiles && ValidateASTInputFilesContent && F.StandardCXXModule && FileChange.Kind == Change::None) FileChange = HasInputContentChanged(FileChange); ``` The patch suggests the solution similar to the presented above and includes a LIT test to verify it.
1 parent 0c42fa3 commit 9a9cff1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,14 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
26302630
F.StandardCXXModule && FileChange.Kind == Change::None)
26312631
FileChange = HasInputContentChanged(FileChange);
26322632

2633+
// When we have StoredTime equal to zero and ValidateASTInputFilesContent,
2634+
// it is better to check the content of the input files because we cannot rely
2635+
// on the file modification time, which will be the same (zero) for these
2636+
// files.
2637+
if (!StoredTime && ValidateASTInputFilesContent &&
2638+
FileChange.Kind == Change::None)
2639+
FileChange = HasInputContentChanged(FileChange);
2640+
26332641
// For an overridden file, there is nothing to validate.
26342642
if (!Overridden && FileChange.Kind != Change::None) {
26352643
if (Complain && !Diags.isDiagnosticInFlight()) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// UNSUPPORTED: system-windows
2+
// RUN: rm -rf %t
3+
// RUN: split-file %s %t
4+
// RUN: cd %t
5+
//
6+
// RUN: cp a1.h a.h
7+
// RUN: %clang_cc1 -fmodules -fvalidate-ast-input-files-content -fno-pch-timestamp -fmodule-map-file=module.modulemap -fmodules-cache-path=%t test1.cpp
8+
// RUN: cp a2.h a.h
9+
// RUN: %clang_cc1 -fmodules -fvalidate-ast-input-files-content -fno-pch-timestamp -fmodule-map-file=module.modulemap -fmodules-cache-path=%t test2.cpp
10+
11+
//--- a1.h
12+
#define FOO
13+
14+
//--- a2.h
15+
#define BAR
16+
17+
//--- module.modulemap
18+
module a {
19+
header "a.h"
20+
}
21+
22+
//--- test1.cpp
23+
#include "a.h"
24+
25+
#ifndef FOO
26+
#error foo
27+
#endif
28+
29+
//--- test2.cpp
30+
#include "a.h"
31+
32+
#ifndef BAR
33+
#error bar
34+
#endif

0 commit comments

Comments
 (0)