[PATCH] D75323: Support relative dest paths in headermap files

Simon Que via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 17:50:20 PST 2020


sque created this revision.
sque added reviewers: vsapsai, arphaman, akyrtzi.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Existing behavior:

- If hmap dest path is absolute: = Look for the file and return it as result. = If file not found, return None.
- If hmap dest path is relative: = Look for entry in headermap with the dest path as key, where the dest is a file that exists. = If key or file not found, return None.

New behavior:

- If hmap dest path is absolute: (unchanged) = look for the file and return it as result. = If not found, return None.
- If hmap dest path is relative: (changed) = Look for entry in headermap with the dest path as key, where the dest is a file that exists. = If key or file not found, fall back to looking for the file directly. = If file not found, return none.

Test case that uses a relative include:

1. Set up input files. mkdir headers touch headers/foo.h echo '#include "foo/foo.h"' > foo.cpp echo 'int main() { return 0; }' >> foo.cpp
2. Create hmap file using hmaptool:
3. https://github.com/llvm-mirror/clang/blob/master/utils/hmaptool/hmaptool
4. The hmap file has the mapping "foo/foo.h" -> "headers/foo.h" echo '{"mappings":{"foo/foo.h":"headers/foo.h"}}' > foo.json hmaptool write foo.json foo.hmap
5. Attempt to compile: clang foo.cpp -o foo -I foo.hmap

Without patch: "fatal error: 'foo/foo.h' file not found"
With patch: successfully compiles.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75323

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===================================================================
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -415,7 +415,9 @@
       FixupSearchPath();
       return *Result;
     }
-  } else if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) {
+    // If lookup failed, fall back to file lookup using relative path directly.
+  }
+  if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) {
     FixupSearchPath();
     return *Res;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75323.247147.patch
Type: text/x-patch
Size: 516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200228/effc5303/attachment.bin>


More information about the cfe-commits mailing list