[clang] [clang][Modules] Disable module map subdirectory search by default (PR #234233)
Cyndy Ishida via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 21 07:58:45 PDT 2026
https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/234233
cbd5ba20d1fa stopped searching the immediate subdirectories of header search paths for module maps on Darwin using SDKs: macOS 15+, iOS 18+, tvOS 18+, watchOS 11+, and visionOS 2+.
Now, disable it by default everywhere. `-fmodulemap-allow-subdirectory-search` is kept as an opt-in for the previous behavior.
>From 561bccea88a15899ea0777b1bfe9fdabd92adc8f Mon Sep 17 00:00:00 2001
From: Cyndy Ishida <cyndy_ishida at apple.com>
Date: Wed, 21 Oct 2026 07:22:25 -0700
Subject: [PATCH] [clang][Modules] Disable module map subdirectory search by
default
cbd5ba20d1fa stopped searching the immediate subdirectories of header
search paths for module maps on Darwin with sufficiently recent
SDKs: macOS 15+, iOS 18+, tvOS 18+, watchOS 11+, and visionOS 2+.
Now, disable it by default everywhere. `-fmodulemap-allow-subdirectory-search` is
kept as an opt-in for the previous behavior.
---
clang/docs/ReleaseNotes.md | 5 +
clang/include/clang/Lex/HeaderSearchOptions.h | 2 +-
clang/include/clang/Options/Options.td | 2 +-
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Driver/ToolChains/Darwin.cpp | 29 -----
.../modulemap-allow-subdirectory-search.c | 114 +++---------------
.../modulemap-allow-subdirectory-search.m | 2 +-
clang/test/Modules/self-import-header.m | 1 +
.../subdirectory-module-maps-working-dir.m | 1 +
9 files changed, 30 insertions(+), 130 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index e13130b789b567..a78b5acdc43eab 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -141,6 +141,11 @@ features cannot lower the translation-unit ABI level;
target triples (except 32b arm targets). Can be disabled via
`-fno-stack-clash-protection`.
+- Clang no longer searches all subdirectories of header search paths
+ for module maps by default when resolving a module import. The previous
+ behavior can be restored with `-fmodulemap-allow-subdirectory-search`,
+ which will be removed in a future release.
+
### Clang Python Bindings Potentially Breaking Changes
- `CompletionChunkKind` instance's `__str__` representation has been adapted to be consistent with other enums in the library.
diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h
index a27af3278b8cff..4bee6a83e61a7c 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -315,7 +315,7 @@ class HeaderSearchOptions {
ModulesPruneNonAffectingModuleMaps(true), ModulesHashContent(false),
ModulesSerializeOnlyPreprocessor(false),
ModulesStrictContextHash(false), ModulesIncludeVFSUsage(false),
- AllowModuleMapSubdirectorySearch(true), LazyLoadModuleMaps(false) {}
+ AllowModuleMapSubdirectorySearch(false), LazyLoadModuleMaps(false) {}
/// AddPath - Add the \p Path path to the specified \p Group list.
void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 64a1183d119f04..bc2d305fc45242 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3928,7 +3928,7 @@ def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, Group<f_Group
HelpText<"Implicitly search the file system for module map files.">,
MarshallingInfoFlag<HeaderSearchOpts<"ImplicitModuleMaps">>;
defm modulemap_allow_subdirectory_search : BoolFOption <"modulemap-allow-subdirectory-search",
- HeaderSearchOpts<"AllowModuleMapSubdirectorySearch">, DefaultTrue,
+ HeaderSearchOpts<"AllowModuleMapSubdirectorySearch">, DefaultFalse,
PosFlag<SetTrue, [], [], "Allow to search for module maps in subdirectories of search paths">,
NegFlag<SetFalse>, BothFlags<[NoXarchOption], [ClangOption, CC1Option]>>;
defm modules : BoolFOption<"modules",
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 608d7bb68a4e6d..10761f9668b12a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4162,8 +4162,8 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
options::OPT_fno_modules_strict_decluse, false))
CmdArgs.push_back("-fmodules-strict-decluse");
- Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
- options::OPT_fno_modulemap_allow_subdirectory_search);
+ Args.addOptInFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
+ options::OPT_fno_modulemap_allow_subdirectory_search);
// -fno-implicit-modules turns off implicitly compiling modules on demand.
bool ImplicitModules = false;
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0fb94d8712e69f..6f18bf14c219fb 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -3638,35 +3638,6 @@ void Darwin::addClangTargetOptions(
if (!DriverArgs.hasArgNoClaim(options::OPT_fdefine_target_os_macros,
options::OPT_fno_define_target_os_macros))
CC1Args.push_back("-fdefine-target-os-macros");
-
- // Disable subdirectory modulemap search on sufficiently recent SDKs.
- if (SDKInfo &&
- !DriverArgs.hasFlag(options::OPT_fmodulemap_allow_subdirectory_search,
- options::OPT_fno_modulemap_allow_subdirectory_search,
- false)) {
- bool RequiresSubdirectorySearch;
- VersionTuple SDKVersion = SDKInfo->getVersion();
- switch (TargetPlatform) {
- default:
- RequiresSubdirectorySearch = true;
- break;
- case MacOS:
- RequiresSubdirectorySearch = SDKVersion < VersionTuple(15, 0);
- break;
- case IPhoneOS:
- case TvOS:
- RequiresSubdirectorySearch = SDKVersion < VersionTuple(18, 0);
- break;
- case WatchOS:
- RequiresSubdirectorySearch = SDKVersion < VersionTuple(11, 0);
- break;
- case XROS:
- RequiresSubdirectorySearch = SDKVersion < VersionTuple(2, 0);
- break;
- }
- if (!RequiresSubdirectorySearch)
- CC1Args.push_back("-fno-modulemap-allow-subdirectory-search");
- }
}
void Darwin::addClangCC1ASTargetOptions(
diff --git a/clang/test/Driver/modulemap-allow-subdirectory-search.c b/clang/test/Driver/modulemap-allow-subdirectory-search.c
index 36ce3bc6cc548d..5ef13cc814cf41 100644
--- a/clang/test/Driver/modulemap-allow-subdirectory-search.c
+++ b/clang/test/Driver/modulemap-allow-subdirectory-search.c
@@ -1,99 +1,21 @@
-// RUN: rm -rf %t
-// RUN: split-file %s %t
+// Check that searching for module maps in subdirectories of search paths is
+// off by default on all platforms and only enabled when explicitly requested.
-// Check that with a sufficiently new SDK not searching for module maps in subdirectories.
+// RUN: %clang -target x86_64-apple-macos10.13 -fmodules %s -### 2>&1 \
+// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %s
+// RUN: %clang -target i386-unknown-linux -fmodules %s -### 2>&1 \
+// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %s
+// RUN: %clang -target x86_64-pc-windows-msvc -fmodules %s -### 2>&1 \
+// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %s
+// RUN: %clang -target x86_64-apple-macos10.13 -fmodules %s -fmodulemap-allow-subdirectory-search \
+// RUN: -fno-modulemap-allow-subdirectory-search -### 2>&1 \
+// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %s
-// New SDK.
-// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -### 2>&1 \
-// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %t/test.c
-// Old SDK.
-// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX14.0.sdk -fmodules %t/test.c -### 2>&1 \
-// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
-// Non-Darwin platform.
-// RUN: %clang -target i386-unknown-linux -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -### 2>&1 \
-// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
-// New SDK overriding the default.
-// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -fmodulemap-allow-subdirectory-search -### 2>&1 \
-// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
+// RUN: %clang -target x86_64-apple-macos10.13 -fmodules %s -fmodulemap-allow-subdirectory-search -### 2>&1 \
+// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %s
+// RUN: %clang -target i386-unknown-linux -fmodules %s -fmodulemap-allow-subdirectory-search -### 2>&1 \
+// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %s
-//--- test.c
-// NO-SUBDIRECTORIES: "-fno-modulemap-allow-subdirectory-search"
-// SEARCH-SUBDIRECTORIES-NOT: "-fno-modulemap-allow-subdirectory-search"
-
-//--- MacOSX15.0.sdk/SDKSettings.json
-{
- "CanonicalName": "macosx15.0",
- "Version": "15.0",
- "IsBaseSDK": "YES",
- "DisplayName": "macOS 15.0",
- "MinimalDisplayName": "15.0",
- "SupportedTargets": {
- "macosx": {
- "PlatformFamilyName": "macOS",
- "PlatformFamilyDisplayName": "macOS",
- "Archs": ["x86_64", "x86_64h", "arm64", "arm64e"], "LLVMTargetTripleVendor": "apple", "LLVMTargetTripleSys": "macos", "LLVMTargetTripleEnvironment": "",
- "BuildVersionPlatformID": "1",
- "ClangRuntimeLibraryPlatformName": "osx",
- "SystemPrefix": "",
- "DefaultDeploymentTarget": "15.0",
- "RecommendedDeploymentTarget": "11.0",
- "MinimumDeploymentTarget": "10.13", "MaximumDeploymentTarget": "15.0.99",
- "ValidDeploymentTargets": ["10.13", "10.14", "10.15", "11.0", "11.1", "11.2", "11.3", "11.4", "11.5", "12.0", "12.2", "12.3", "12.4", "13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "14.0", "14.1", "14.2", "14.3", "14.4", "14.5", "14.6", "15.0"]
- },
- "iosmac": {
- "Archs": ["x86_64", "x86_64h", "arm64", "arm64e"], "LLVMTargetTripleVendor": "apple", "LLVMTargetTripleSys": "ios", "LLVMTargetTripleEnvironment": "macabi",
- "BuildVersionPlatformID": "6",
- "ClangRuntimeLibraryPlatformName": "osx",
- "SystemPrefix": "/System/iOSSupport",
- "DefaultDeploymentTarget": "18.0",
- "RecommendedDeploymentTarget": "14.2",
- "MinimumDeploymentTarget": "13.1", "MaximumDeploymentTarget": "18.0.99",
- "ValidDeploymentTargets": ["13.1", "13.2", "13.3", "13.3.1", "13.4", "13.5", "14.0", "14.1", "14.2", "14.3", "14.4", "14.5", "14.6", "14.7", "15.0", "15.2", "15.3", "15.4", "15.5", "15.6", "16.0", "16.1", "16.2", "16.3", "16.4", "16.5", "16.6", "17.0", "17.1", "17.2", "17.3", "17.4", "17.5", "17.6", "18.0"]
- }
- },
- "VersionMap": {
- "macOS_iOSMac": {"10.15": "13.1", "10.15.1": "13.2", "10.15.2": "13.3", "10.15.3": "13.3.1", "10.15.4": "13.4", "10.15.5": "13.5", "11.0": "14.2", "11.0.1": "14.2", "11.1": "14.3", "11.2": "14.4", "11.3": "14.5", "11.4": "14.6", "11.5": "14.7", "12.0": "15.0", "12.0.1": "15.0", "12.1": "15.2", "12.2": "15.3", "12.3": "15.4", "12.4": "15.5", "12.5": "15.6", "13.0": "16.1", "13.1": "16.2", "13.2": "16.3", "13.3": "16.4", "13.4": "16.5", "13.5": "16.6", "14.0": "17.0", "14.1": "17.1", "14.2": "17.2", "14.3": "17.3", "14.4": "17.4", "14.5": "17.5", "14.6": "17.6", "15.0": "18.0"},
- "iOSMac_macOS": {"13.1": "10.15", "13.2": "10.15.1", "13.3": "10.15.2", "13.3.1": "10.15.3", "13.4": "10.15.4", "13.5": "10.15.5", "14.0": "11.0", "14.1": "11.0", "14.2": "11.0", "14.3": "11.1", "14.4": "11.2", "14.5": "11.3", "14.6": "11.4", "14.7": "11.5", "15.0": "12.0", "15.2": "12.1", "15.3": "12.2", "15.4": "12.3", "15.5": "12.4", "15.6": "12.5", "16.0": "13.0", "16.1": "13.0", "16.2": "13.1", "16.3": "13.2", "16.4": "13.3", "16.5": "13.4", "16.6": "13.5", "17.0": "14.0", "17.1": "14.1", "17.2": "14.2", "17.3": "14.3", "17.4": "14.4", "17.5": "14.5", "17.6": "14.6", "18.0": "15.0"}
- },
- "DefaultDeploymentTarget": "15.0",
- "MaximumDeploymentTarget": "15.0.99"
-}
-
-//--- MacOSX14.0.sdk/SDKSettings.json
-{
- "CanonicalName": "macosx14.0",
- "Version": "14.0",
- "IsBaseSDK": "YES",
- "DisplayName": "macOS 14.0",
- "MinimalDisplayName": "14.0",
- "SupportedTargets": {
- "macosx": {
- "PlatformFamilyName": "macOS",
- "PlatformFamilyDisplayName": "macOS",
- "Archs": ["x86_64", "x86_64h", "arm64", "arm64e"], "LLVMTargetTripleVendor": "apple", "LLVMTargetTripleSys": "macos", "LLVMTargetTripleEnvironment": "",
- "BuildVersionPlatformID": "1",
- "ClangRuntimeLibraryPlatformName": "osx",
- "SystemPrefix": "",
- "DefaultDeploymentTarget": "14.0",
- "RecommendedDeploymentTarget": "10.14.6",
- "MinimumDeploymentTarget": "10.13", "MaximumDeploymentTarget": "14.0.99",
- "ValidDeploymentTargets": ["10.13", "10.14", "10.15", "11.0", "11.1", "11.2", "11.3", "11.4", "11.5", "12.0", "12.2", "12.3", "12.4", "13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "14.0"]
- },
- "iosmac": {
- "Archs": ["x86_64", "x86_64h", "arm64", "arm64e"], "LLVMTargetTripleVendor": "apple", "LLVMTargetTripleSys": "ios", "LLVMTargetTripleEnvironment": "macabi",
- "BuildVersionPlatformID": "6",
- "ClangRuntimeLibraryPlatformName": "osx",
- "SystemPrefix": "/System/iOSSupport",
- "DefaultDeploymentTarget": "17.0",
- "RecommendedDeploymentTarget": "13.1",
- "MinimumDeploymentTarget": "13.1", "MaximumDeploymentTarget": "17.0.99",
- "ValidDeploymentTargets": ["13.1", "13.2", "13.3", "13.3.1", "13.4", "13.5", "14.0", "14.1", "14.2", "14.3", "14.4", "14.5", "14.6", "14.7", "15.0", "15.2", "15.3", "15.4", "15.5", "15.6", "16.0", "16.1", "16.2", "16.3", "16.4", "16.5", "16.6", "17.0"]
- }
- },
- "VersionMap": {
- "macOS_iOSMac": {"10.15": "13.1", "10.15.1": "13.2", "10.15.2": "13.3", "10.15.3": "13.3.1", "10.15.4": "13.4", "10.15.5": "13.5", "11.0": "14.2", "11.0.1": "14.2", "11.1": "14.3", "11.2": "14.4", "11.3": "14.5", "11.4": "14.6", "11.5": "14.7", "12.0": "15.0", "12.0.1": "15.0", "12.1": "15.2", "12.2": "15.3", "12.3": "15.4", "12.4": "15.5", "12.5": "15.6", "13.0": "16.1", "13.1": "16.2", "13.2": "16.3", "13.3": "16.4", "13.4": "16.5", "13.5": "16.6", "14.0": "17.0"},
- "iOSMac_macOS": {"13.1": "10.15", "13.2": "10.15.1", "13.3": "10.15.2", "13.3.1": "10.15.3", "13.4": "10.15.4", "13.5": "10.15.5", "14.0": "11.0", "14.1": "11.0", "14.2": "11.0", "14.3": "11.1", "14.4": "11.2", "14.5": "11.3", "14.6": "11.4", "14.7": "11.5", "15.0": "12.0", "15.2": "12.1", "15.3": "12.2", "15.4": "12.3", "15.5": "12.4", "15.6": "12.5", "16.0": "13.0", "16.1": "13.0", "16.2": "13.1", "16.3": "13.2", "16.4": "13.3", "16.5": "13.4", "16.6": "13.5", "17.0": "14.0"}
- },
- "DefaultDeploymentTarget": "14.0",
- "MaximumDeploymentTarget": "14.0.99"
-}
+// NO-SUBDIRECTORIES-NOT: "-fmodulemap-allow-subdirectory-search"
+// NO-SUBDIRECTORIES-NOT: "-fno-modulemap-allow-subdirectory-search"
+// SEARCH-SUBDIRECTORIES: "-fmodulemap-allow-subdirectory-search"
diff --git a/clang/test/Modules/modulemap-allow-subdirectory-search.m b/clang/test/Modules/modulemap-allow-subdirectory-search.m
index ef6f9b1009babc..02f11c1551bde2 100644
--- a/clang/test/Modules/modulemap-allow-subdirectory-search.m
+++ b/clang/test/Modules/modulemap-allow-subdirectory-search.m
@@ -1,7 +1,7 @@
// RUN: rm -rf %t
// RUN: split-file %s %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.m
+// RUN: not %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.m
// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.m -fmodulemap-allow-subdirectory-search
// RUN: not %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.m -fno-modulemap-allow-subdirectory-search
diff --git a/clang/test/Modules/self-import-header.m b/clang/test/Modules/self-import-header.m
index 9cadcc4762e05c..aa3a2c16e8423e 100644
--- a/clang/test/Modules/self-import-header.m
+++ b/clang/test/Modules/self-import-header.m
@@ -1,6 +1,7 @@
// REQUIRES: x86-registered-target
// RUN: rm -rf %t
// RUN: %clang -fsyntax-only -isysroot %S/Inputs/System/usr/include -fmodules -fmodules-cache-path=%t \
+// RUN: -fmodulemap-allow-subdirectory-search \
// RUN: -target x86_64-darwin \
// RUN: -F %S -F %S/Inputs/self-import-header -I %S/Inputs/self-import-header \
// RUN: %s -D__need_wint_t -Werror=implicit-function-declaration
diff --git a/clang/test/Modules/subdirectory-module-maps-working-dir.m b/clang/test/Modules/subdirectory-module-maps-working-dir.m
index 43488e8d136011..7415acba91a048 100644
--- a/clang/test/Modules/subdirectory-module-maps-working-dir.m
+++ b/clang/test/Modules/subdirectory-module-maps-working-dir.m
@@ -1,5 +1,6 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN: -fmodulemap-allow-subdirectory-search \
// RUN: -working-directory %S/Inputs \
// RUN: -I subdirectory-module-maps-working-dir \
// RUN: %s -Werror=implicit-function-declaration -verify
More information about the cfe-commits
mailing list