[clang] [clang][Modules] Restore module search on the MODULE_MAP_FILE relocation check (PR #219521)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 10:15:37 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-modules

Author: Qiongsi Wu (qiongsiwu)

<details>
<summary>Changes</summary>

 cf8597bd3b87 (#<!-- -->181836) refactored the two relocation-check call sites in ASTReader into `getModuleForRelocationChecks` with the `DirectoryCheck` flag passed to `lookupModule`. The change did not preserve the original functionality for `ASTReader::ReadModuleMapFileBlock` (https://github.com/llvm/llvm-project/commit/cf8597bd3b87aeed6696454f22311e86ed70138f#diff-c61a3cce4bfa099b5af032fa83cbf1563f0af4bf58dc112b39571d74b6b681c1L4586). `ASTReader::ReadModuleMapFileBlock`'s `lookupModule` relied on the default value of `AllowSearch`, which is `true`. Passing `false` to `getModuleForRelocationChecks` changes how module lookup works, and clang can prematurely stop looking when a `MODULE_DIRECTORY` is not present.

Assisted-by: Claude (Claude-Opus-5)

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTReader.cpp (+1-1) 
- (added) clang/test/Modules/relocation-check-no-module-directory.c (+29) 


``````````diff
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index b36e28819b9e1..477b41e344472 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3243,7 +3243,7 @@ ASTReader::getModuleForRelocationChecks(ModuleFile &F, bool DirectoryCheck) {
   // check).
   Module *M = PP.getHeaderSearchInfo().lookupModule(
       F.ModuleName, DirectoryCheck ? SourceLocation() : F.ImportLoc,
-      /*AllowSearch=*/DirectoryCheck,
+      /*AllowSearch=*/true,
       /*AllowExtraModuleMapSearch=*/DirectoryCheck);
 
   return {M, IgnoreError};
diff --git a/clang/test/Modules/relocation-check-no-module-directory.c b/clang/test/Modules/relocation-check-no-module-directory.c
new file mode 100644
index 0000000000000..0bcd06e367ecc
--- /dev/null
+++ b/clang/test/Modules/relocation-check-no-module-directory.c
@@ -0,0 +1,29 @@
+// Check that a transitively imported module can still be resolved when the PCM
+// has no MODULE_DIRECTORY record, which -fmodule-file-home-is-cwd suppresses.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Case 1: the load of the transitively imported 'Other' should succeed.
+// RUN: %clang -fmodules -fimplicit-module-maps -fsyntax-only %t/tu.c \
+// RUN:   -fmodules-cache-path=%t/cache -I%t/pathB -I%t/pathC \
+// RUN:   -Xclang -fmodule-file-home-is-cwd
+
+// Case 2: the same load must not crash when module validation is disabled.
+// RUN: %clang -fmodules -fimplicit-module-maps -fsyntax-only %t/tu.c \
+// RUN:   -fmodules-cache-path=%t/cache-novalidate -I%t/pathB -I%t/pathC \
+// RUN:   -Xclang -fmodule-file-home-is-cwd -Xclang -fno-validate-pch
+
+//--- pathB/module.modulemap
+module Dep { header "Dep.h" export * }
+//--- pathB/Dep.h
+#include "Other.h"
+int dep(void);
+
+//--- pathC/module.modulemap
+module Other { header "Other.h" }
+//--- pathC/Other.h
+int other(void);
+
+//--- tu.c
+#include "Dep.h"

``````````

</details>


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


More information about the cfe-commits mailing list