[PATCH] D107921: [Modules] Fix bug where header resolution in modules doesn't work when compiling with relative paths.

Amy Huang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 12 17:24:03 PDT 2021


akhuang updated this revision to Diff 366153.
akhuang added a comment.

add case for include_nexts; I don't entirely understand this part of the code so not sure if it's what we want, but it seems to make building with -no-canonical-prefixes happier


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107921/new/

https://reviews.llvm.org/D107921

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===================================================================
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -819,9 +819,24 @@
       bool IncluderIsSystemHeader =
           Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User :
           BuildSystemModule;
-      if (Optional<FileEntryRef> FE = getFileAndSuggestModule(
-              TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,
-              RequestingModule, SuggestedModule)) {
+
+      Optional<FileEntryRef> FE = getFileAndSuggestModule(
+          TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,
+          RequestingModule, SuggestedModule);
+
+      // If this is a system header, we should also search from the current
+      // working directory and not the directory of the module map.
+      if (!FE && IncluderIsSystemHeader) {
+        // If this was an #include_next "/file", fail.
+        if (!FromDir)
+          return None;
+
+        FE = getFileAndSuggestModule(
+            Filename, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,
+            RequestingModule, SuggestedModule);
+      }
+
+      if (FE) {
         if (!Includer) {
           assert(First && "only first includer can have no file");
           return FE;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107921.366153.patch
Type: text/x-patch
Size: 1333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210813/9d4d9b89/attachment-0001.bin>


More information about the cfe-commits mailing list