[clang] [clang][modules] Add warning for symlinks to modular headers (PR #188059)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 15:28:25 PDT 2026
================
@@ -1896,6 +1916,77 @@ static bool suggestModule(HeaderSearch &HS, ModuleMap::KnownHeader Module,
return true;
}
+void HeaderSearch::diagnoseUncoveredSymlink(FileEntryRef File,
+ ModuleMap::KnownHeader &Module,
+ const DirectoryEntry *Root) {
+ if (!Module)
+ return;
+
+ if (!HSOpts.ImplicitModuleMaps || Module.getModule()->isPartOfFramework() ||
+ !Module.getModule()->isModuleMapModule())
+ return;
+
+ if (Diags.isIgnored(diag::warn_mmap_deprecated_symlink_to_modular_header,
+ Module.getModule()->DefinitionLoc))
+ return;
+
+ if (File.isDeviceFile() || File.isNamedPipe())
+ return;
+
+ llvm::SmallString<128> AbsPath(File.getName());
+ FileMgr.makeAbsolutePath(AbsPath);
+ llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
+
+ // NOTE: This path may be redirected, LLVM's VFS does not model symlinks, so
+ // it's possible this fails. The diagnostic is worded as such.
+ llvm::SmallString<128> LinkTarget;
+ if (llvm::sys::fs::readlink(AbsPath, LinkTarget))
+ return;
----------------
jansvoboda11 wrote:
We chatted offline and I think this is fine for the time being as a best-effort approach.
https://github.com/llvm/llvm-project/pull/188059
More information about the cfe-commits
mailing list