aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2022-12-01 19:09:09 -0800
committerJan Svoboda <jan_svoboda@apple.com>2022-12-01 19:59:54 -0800
commit935a07ed21434825a96eb6d3acd2163edd0abe88 (patch)
tree10aa8785ff11ae65a2ae2b396050311962086b8b /clang/lib/Lex/ModuleMap.cpp
parentf9ed86a5fd952864da44c1f51b978e467fc4cdc6 (diff)
downloadllvm-935a07ed21434825a96eb6d3acd2163edd0abe88.zip
llvm-935a07ed21434825a96eb6d3acd2163edd0abe88.tar.gz
llvm-935a07ed21434825a96eb6d3acd2163edd0abe88.tar.bz2
[clang][deps][lex] Avoid canonicalization of remapped framework directories
In D134923, the scanner introduced canonicalization of framework directories when reporting module map paths in order to increase module sharing. However, if we canonicalize framework directory that plays a role in a VFS remapping, and later try to use that module map to build the module, header lookup can fail. This happens when the module headers are remapped using the original framework path. This patch fixes that. The implementation relies on the fact that the chain of directories in VFS remapping are assigned `DirectoryEntry` objects distinct from their on-disk counterparts. If we detect that case, we avoid the canonicalization. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D135841
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 9ff0204..4e86c5c 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1303,9 +1303,16 @@ ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl<char> &Path) {
// Canonicalize the directory.
StringRef CanonicalDir = FM.getCanonicalName(*DirEntry);
if (CanonicalDir != Dir) {
- bool Done = llvm::sys::path::replace_path_prefix(Path, Dir, CanonicalDir);
- (void)Done;
- assert(Done && "Path should always start with Dir");
+ auto CanonicalDirEntry = FM.getDirectory(CanonicalDir);
+ // Only use the canonicalized path if it resolves to the same entry as the
+ // original. This is not true if there's a VFS overlay on top of a FS where
+ // the directory is a symlink. The overlay would not remap the target path
+ // of the symlink to the same directory entry in that case.
+ if (CanonicalDirEntry && *CanonicalDirEntry == *DirEntry) {
+ bool Done = llvm::sys::path::replace_path_prefix(Path, Dir, CanonicalDir);
+ (void)Done;
+ assert(Done && "Path should always start with Dir");
+ }
}
// In theory, the filename component should also be canonicalized if it