[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps
Ivan Murashko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat May 6 08:50:03 PDT 2023
ivanmurashko updated this revision to Diff 520096.
ivanmurashko added a comment.
rebase
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/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,53 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %hmaptool write a.hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
+//
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: sed -e "s|OUTPUTS_DIR|%t|g" -e "s|\\\\|/|g" b.hmap.json > hmap.json
+// RUN: %hmaptool write hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
+
+//--- After/Mapping.h
+#ifdef FOO
+#error foo
+#endif
+
+//--- a.hmap.json
+{
+ "mappings" :
+ {
+ "Before/Mapping.h" : "After/Mapping.h",
+ "After/Mapping.h" : "After/Mapping.h"
+ }
+}
+
+//--- b.hmap.json
+{
+ "mappings" :
+ {
+ "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h"
+ }
+}
+
+//--- module.modulemap
+module a {
+ header "After/Mapping.h"
+}
+
+
+//--- test.cpp
+#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/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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103930.520096.patch
Type: text/x-patch
Size: 2747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230506/899d3ac7/attachment.bin>
More information about the cfe-commits
mailing list