[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

Andrew Gallagher via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 10 09:14:01 PDT 2021


andrewjcg updated this revision to Diff 351195.
andrewjcg 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/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,20 @@
     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;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103930.351195.patch
Type: text/x-patch
Size: 3458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210610/f1965ff1/attachment-0001.bin>


More information about the cfe-commits mailing list