andrewjcg updated this revision to Diff 352299.
andrewjcg added a comment.
feedback
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,29 @@
+// 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
+// This include will fail if modules weren't used. The include name itself
+// 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
@@ -417,7 +417,8 @@
IsInHeaderMap = true;
- auto FixupSearchPath = [&]() {
+ auto FixupSearchPathAndFindUsableModule =
+ [&](auto file) -> Optional<FileEntryRef> {
if (SearchPath) {
StringRef SearchPathRef(getName());
SearchPath->clear();
@@ -427,6 +428,12 @@
RelativePath->clear();
RelativePath->append(Filename.begin(), Filename.end());
}
+ if (!HS.findUsableModuleForHeader(
+ &file.getFileEntry(), file.getFileEntry().getDir(),
+ RequestingModule, SuggestedModule, isSystemHeaderDirectory())) {
+ return None;
+ }
+ return file;
};
// Check if the headermap maps the filename to a framework include
@@ -437,12 +444,10 @@
Filename = StringRef(MappedName.begin(), MappedName.size());
Optional<FileEntryRef> Result = HM->LookupFile(Filename, HS.getFileMgr());
if (Result) {
- FixupSearchPath();
- return *Result;
+ return FixupSearchPathAndFindUsableModule(*Result);
}
} else if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) {
- FixupSearchPath();
- return *Res;
+ return FixupSearchPathAndFindUsableModule(*Res);
}
return None;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits