diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -438,10 +438,20 @@ Optional Result = HM->LookupFile(Filename, HS.getFileMgr()); if (Result) { FixupSearchPath(); + if (!HS.findUsableModuleForHeader( + &Result->getFileEntry(), Result->getFileEntry().getDir(), + RequestingModule, SuggestedModule, isSystemHeaderDirectory())) { + return None; + } return *Result; } } else if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) { FixupSearchPath(); + if (!HS.findUsableModuleForHeader( + &Res->getFileEntry(), Res->getFileEntry().getDir(), + RequestingModule, SuggestedModule, isSystemHeaderDirectory())) { + return None; + } return *Res; } diff --git a/clang/test/Modules/Inputs/implicit-module-header-maps/a.h b/clang/test/Modules/Inputs/implicit-module-header-maps/a.h new file mode 100644 --- /dev/null +++ b/clang/test/Modules/Inputs/implicit-module-header-maps/a.h @@ -0,0 +1,3 @@ +#ifdef FOO +#error foo +#endif diff --git a/clang/test/Modules/Inputs/implicit-module-header-maps/a.hmap.json b/clang/test/Modules/Inputs/implicit-module-header-maps/a.hmap.json new file mode 100644 --- /dev/null +++ b/clang/test/Modules/Inputs/implicit-module-header-maps/a.hmap.json @@ -0,0 +1,7 @@ +{ + "mappings" : + { + "Before/Mapping.h" : "After/Mapping.h", + "After/Mapping.h" : "After/Mapping.h" + } +} diff --git a/clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap b/clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap new file mode 100644 --- /dev/null +++ b/clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap @@ -0,0 +1,3 @@ +module a { + header "After/Mapping.h" +} diff --git a/clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json b/clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json new file mode 100644 --- /dev/null +++ b/clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json @@ -0,0 +1,6 @@ +{ + "mappings" : + { + "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h" + } +} diff --git a/clang/test/Modules/implicit-module-header-maps.cpp b/clang/test/Modules/implicit-module-header-maps.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Modules/implicit-module-header-maps.cpp @@ -0,0 +1,27 @@ +// RUN: rm -rf %T +// RUN: mkdir %T +// RUN: cd %T +// +// RUN: %hmaptool write %S/Inputs/implicit-module-header-maps/a.hmap.json %T/hmap +// +// RUN: mkdir -p %T/After +// RUN: cp %S/Inputs/implicit-module-header-maps/a.h %T/After/Mapping.h +// RUN: cp %S/Inputs/implicit-module-header-maps/a.module.modulemap %T/module.modulemap +// +// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=%T/module.modulemap -fsyntax-only %s -I %T/hmap +// +// RUN: rm -rf %T +// RUN: mkdir %T +// RUN: cd %T +// +// RUN: sed -e "s:OUTPUTS_DIR:%T:g" %S/Inputs/implicit-module-header-maps/b.hmap.json > %T/hmap.json +// RUN: %hmaptool write %T/hmap.json %T/hmap +// +// RUN: mkdir -p %T/After +// RUN: cp %S/Inputs/implicit-module-header-maps/a.h %T/After/Mapping.h +// RUN: cp %S/Inputs/implicit-module-header-maps/a.module.modulemap %T/module.modulemap +// +// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=%T/module.modulemap -fsyntax-only %s -I %T/hmap + +#define FOO +#include "Before/Mapping.h"