https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/234233
>From 4535543474495774ff956dd957b16708b632f0fe Mon Sep 17 00:00:00 2001 From: Cyndy Ishida <[email protected]> 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/modulemap-locations.m | 2 +- clang/test/Modules/self-import-header.m | 2 +- .../subdirectory-module-maps-working-dir.m | 1 + .../SymbolFile/DWARF/x86/module-ownership.mm | 2 +- 11 files changed, 32 insertions(+), 133 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/modulemap-locations.m b/clang/test/Modules/modulemap-locations.m index 330a03d1fb6335..7f23db92ce3de4 100644 --- a/clang/test/Modules/modulemap-locations.m +++ b/clang/test/Modules/modulemap-locations.m @@ -1,5 +1,5 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/ModuleMapLocations/Module_ModuleMap -I %S/Inputs/ModuleMapLocations/Both -F %S/Inputs/ModuleMapLocations -I %S/Inputs/ModuleMapLocations -F %S/Inputs -x objective-c -fsyntax-only %s -verify -Wno-private-module +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/ModuleMapLocations/Module_ModuleMap -I %S/Inputs/ModuleMapLocations/Both -I %S/Inputs/ModuleMapLocations/Module_Map -F %S/Inputs/ModuleMapLocations -I %S/Inputs/ModuleMapLocations -F %S/Inputs -x objective-c -fsyntax-only %s -verify -Wno-private-module // regular @import module_map; // expected-warning@*{{as a module map name is deprecated, rename it to module.modulemap}} diff --git a/clang/test/Modules/self-import-header.m b/clang/test/Modules/self-import-header.m index 9cadcc4762e05c..b257ece2fc21a0 100644 --- a/clang/test/Modules/self-import-header.m +++ b/clang/test/Modules/self-import-header.m @@ -2,7 +2,7 @@ // RUN: rm -rf %t // RUN: %clang -fsyntax-only -isysroot %S/Inputs/System/usr/include -fmodules -fmodules-cache-path=%t \ // RUN: -target x86_64-darwin \ -// RUN: -F %S -F %S/Inputs/self-import-header -I %S/Inputs/self-import-header \ +// RUN: -F %S -F %S/Inputs/self-import-header -I %S/Inputs/self-import-header/depend_builtin \ // RUN: %s -D__need_wint_t -Werror=implicit-function-declaration @import af; 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 diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm b/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm index 27aa1365ab54c4..7342cecd049a73 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm @@ -1,7 +1,7 @@ // RUN: rm -rf %t.cache // RUN: %clangxx --target=x86_64-apple-macosx -g -gmodules -Wno-objc-root-class \ // RUN: -fmodules -fmodules-cache-path=%t.cache \ -// RUN: -c -o %t.o %s -I%S/Inputs +// RUN: -c -o %t.o %s -I%S/Inputs/ModuleOwnership // RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck --check-prefix CHECK-ANON-S1 %s // RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck --check-prefix CHECK-ANON-S2 %s // RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck %s _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
