ivanmurashko updated this revision to Diff 517159. ivanmurashko added a comment.
Commandeer the diff from @andrewjcg and made some chnages at the code (get it compatible with latest clang source code) and at the tests (move modules artefacts to temp folder to make the test execution more stable). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D103930/new/ https://reviews.llvm.org/D103930 Files: clang/lib/Lex/HeaderSearch.cpp clang/test/Modules/Inputs/implicit-module-header-maps/a.h clang/test/Modules/Inputs/implicit-module-header-maps/a.hmap.json clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json clang/test/Modules/implicit-module-header-maps.cpp
Index: clang/test/Modules/implicit-module-header-maps.cpp =================================================================== --- /dev/null +++ clang/test/Modules/implicit-module-header-maps.cpp @@ -0,0 +1,32 @@ +// 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 -fmodules-cache-path=%t +// +// 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 -fmodules-cache-path=%t + +#define FOO +// This include will fail if: +// 1) modules are't used, as the `FOO` define will propagate into the included +// header and trip a `#error`, or +// 2) header maps aren't usesd, as the header name doesn't exist and relies on +// the header map to remap it to the real header. +#include "Before/Mapping.h" Index: clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/implicit-module-header-maps/b.hmap.json @@ -0,0 +1,6 @@ +{ + "mappings" : + { + "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h" + } +} Index: clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/implicit-module-header-maps/a.module.modulemap @@ -0,0 +1,3 @@ +module a { + header "After/Mapping.h" +} Index: clang/test/Modules/Inputs/implicit-module-header-maps/a.hmap.json =================================================================== --- /dev/null +++ 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" + } +} Index: clang/test/Modules/Inputs/implicit-module-header-maps/a.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/implicit-module-header-maps/a.h @@ -0,0 +1,3 @@ +#ifdef FOO +#error foo +#endif Index: clang/lib/Lex/HeaderSearch.cpp =================================================================== --- clang/lib/Lex/HeaderSearch.cpp +++ clang/lib/Lex/HeaderSearch.cpp @@ -491,7 +491,8 @@ IsInHeaderMap = true; - auto FixupSearchPath = [&]() { + auto FixupSearchPathAndFindUsableModule = + [&](auto File) -> OptionalFileEntryRef { if (SearchPath) { StringRef SearchPathRef(getName()); SearchPath->clear(); @@ -501,6 +502,12 @@ RelativePath->clear(); RelativePath->append(Filename.begin(), Filename.end()); } + if (!HS.findUsableModuleForHeader( + &File.getFileEntry(), File.getFileEntry().getDir(), + RequestingModule, SuggestedModule, isSystemHeaderDirectory())) { + return std::nullopt; + } + return File; }; // Check if the headermap maps the filename to a framework include @@ -513,8 +520,7 @@ } if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest, OpenFile)) { - FixupSearchPath(); - return *Res; + return FixupSearchPathAndFindUsableModule(*Res); } // Header maps need to be marked as used whenever the filename matches.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits