andrewjcg created this revision. Herald added a subscriber: wenlei. andrewjcg updated this revision to Diff 350757. andrewjcg added a comment. andrewjcg edited the summary of this revision. andrewjcg added reviewers: bruno, rsmith. andrewjcg published this revision for review. Herald added a project: clang. Herald added a subscriber: cfe-commits.
add tests Previously, if a header was found via in a header map, and not just remapped. we wouldn't also find the module it maps to when using implicit modules (for module maps that were explicitly loaded). This diff just updates these code paths to also locate the owning module via `findUsableModuleForHeader`. Repository: rG LLVM Github Monorepo 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,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" 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 @@ -438,10 +438,22 @@ Optional<FileEntryRef> 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; }
Index: clang/test/Modules/implicit-module-header-maps.cpp =================================================================== --- /dev/null +++ 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" 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 @@ -438,10 +438,22 @@ Optional<FileEntryRef> 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits