[clang] [clang][DepScan] Support subdirectory seach in getModuleMapsForModules (PR #238860)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 08:48:37 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)

<details>
<summary>Changes</summary>

Respect resolving modulemaps with `-fmodulemap-allow-subdirectory-search` in `getModuleMapsForModules` to match the normal scan's lookup. Note this option is default disabled.

---
Full diff: https://github.com/llvm/llvm-project/pull/238860.diff


2 Files Affected:

- (modified) clang/lib/DependencyScanning/DependencyScanningWorker.cpp (+2-1) 
- (modified) clang/unittests/Tooling/DependencyScannerTest.cpp (+31) 


``````````diff
diff --git a/clang/lib/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/DependencyScanning/DependencyScanningWorker.cpp
index 410f38c333a81e..ed620617d6fd61 100644
--- a/clang/lib/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/DependencyScanning/DependencyScanningWorker.cpp
@@ -737,7 +737,8 @@ class ModuleMapLookup {
       // Skip over prebuilt modules.
       if (HasPrebuiltModules && !HS.getPrebuiltModuleFileName(Name).empty())
         continue;
-      OptionalFileEntryRef File = HS.lookupModuleMapFileForModule(Name);
+      OptionalFileEntryRef File = HS.lookupModuleMapFileForModule(
+          Name, /*AllowExtraModuleMapSearch=*/true);
       // Skip over modules that didn't find a modulemap.
       if (!File)
         continue;
diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp
index f9a60b9c1f6e98..8e2f0455288fd8 100644
--- a/clang/unittests/Tooling/DependencyScannerTest.cpp
+++ b/clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -534,6 +534,37 @@ TEST_F(GetModuleMapsForModulesTest, NotFound) {
   EXPECT_TRUE(ModuleMaps->empty());
 }
 
+// Verify a modulemap that can only be resolved with subdirectory search, fails
+// when disabled but passes otherwise.
+TEST_F(GetModuleMapsForModulesTest, SubdirectorySearch) {
+  addFile("/root/test.m", "\n");
+  addFile("/root/a/Sub/module.modulemap", "module A { header \"a.h\" }\n");
+  addFile("/root/a/Sub/a.h", "\n");
+
+  std::pair<StringRef, StringRef> Cases[] = {
+      {"-fmodulemap-allow-subdirectory-search", "/root/a/Sub/module.modulemap"},
+      {"-fno-modulemap-allow-subdirectory-search", ""}};
+  for (auto [Flag, Expected] : Cases) {
+    SCOPED_TRACE(Flag);
+    std::vector<std::string> CommandLine = {
+        "clang",     "-target", "x86_64-apple-macosx10.7",
+        "-c",        "test.m",  "-fmodules",
+        "-I/root/a", Flag.str()};
+
+    TextDiagnosticBuffer ScanDiags;
+    EXPECT_EQ(llvm::sys::path::convert_to_slash(
+                  scanModuleMapFile(CommandLine, "A", ScanDiags)),
+              Expected);
+
+    TextDiagnosticBuffer LookupDiags;
+    std::optional<llvm::StringMap<std::string>> ModuleMaps =
+        getModuleMaps(CommandLine, {"A"}, LookupDiags);
+    ASSERT_TRUE(ModuleMaps);
+    EXPECT_EQ(llvm::sys::path::convert_to_slash(ModuleMaps->lookup("A")),
+              Expected);
+  }
+}
+
 // Verify a command line that cannot be set up reports
 // an error.
 TEST_F(GetModuleMapsForModulesTest, IllFormedCommandLine) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/238860


More information about the cfe-commits mailing list