Skip to content

Commit 64bb60a

Browse files
authored
[Modules] Don't fail when an unused textual header is missing. (#138227)
According to the documentation > A header declaration that does not contain `exclude` nor `textual` specifies a header that contributes to the enclosing module. Which means that `exclude` and `textual` header don't contribute to the enclosing module and their presence isn't required to build such a module. The keywords tell clang how a header should be treated in a context of the module but they don't add headers to the module. When a textual header *is* used, clang still emits "file not found" error pointing to the location where the missing file is included.
1 parent 5b7ccdc commit 64bb60a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

clang/lib/Lex/ModuleMap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ void ModuleMap::resolveHeader(Module *Mod,
310310
} else if (Header.HasBuiltinHeader && !Header.Size && !Header.ModTime) {
311311
// There's a builtin header but no corresponding on-disk header. Assume
312312
// this was supposed to modularize the builtin header alone.
313-
} else if (Header.Kind == Module::HK_Excluded) {
314-
// Ignore missing excluded header files. They're optional anyway.
313+
} else if ((Header.Kind == Module::HK_Excluded) ||
314+
(Header.Kind == Module::HK_Textual)) {
315+
// Ignore excluded and textual header files as a module can be built with
316+
// such headers missing.
315317
} else {
316318
// If we find a module that has a missing header, we mark this module as
317319
// unavailable and store the header directive for displaying diagnostics.

clang/test/Modules/Inputs/submodules/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ module missing_umbrella_with_inferred_submodules {
3030
module * { export * }
3131
export *
3232
}
33+
34+
module missing_textual_header {
35+
textual header "missing_textual.h"
36+
}

clang/test/Modules/missing-header.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
@import missing_unavailable_headers.not_missing; // OK
99
// CHECK-NOT: missing_unavailable_headers
1010

11+
@import missing_textual_header; // OK
12+
// CHECK-NOT: missing_textual_header
13+
1114
@import missing_headers;
1215
// CHECK: module.modulemap:15:27: error: header 'missing.h' not found
1316
// CHECK: could not build module 'missing_headers'

0 commit comments

Comments
 (0)