https://github.com/qiongsiwu created https://github.com/llvm/llvm-project/pull/219521
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) >From d2a591e2affcf5e1d830a48ec50503180e7b237a Mon Sep 17 00:00:00 2001 From: Qiongsi Wu <[email protected]> Date: Fri, 28 Aug 2026 09:28:32 -0700 Subject: [PATCH] Fixing a relocation check regression where the pcm file does not have MODULE_DIRECTORY record. --- clang/lib/Serialization/ASTReader.cpp | 2 +- .../relocation-check-no-module-directory.c | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 clang/test/Modules/relocation-check-no-module-directory.c 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" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
