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;
   }


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;
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to