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"