[clang] [clang] Fix incorrect filenames for hardlinks (PR #189475)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 08:21:38 PDT 2026


================
@@ -542,14 +570,26 @@ FileID SourceManager::createFileID(FileEntryRef SourceFile,
                                    SourceLocation::UIntTy LoadedOffset) {
   SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile,
                                                      isSystem(FileCharacter));
+  SrcMgr::ContentCache *Cache = &IR;
+  StringRef Filename = SourceFile.getName();
+
+  if (IR.OrigEntry && !IR.OrigEntry->isSameRef(SourceFile)) {
+    if (pathDiffersIgnoringWindowsSlashes(*IR.OrigEntry, SourceFile)) {
+      Cache = cloneContentCache(ContentCacheAlloc, IR);
+      Cache->OrigEntry = SourceFile;
+      FileIDContentCaches.push_back(Cache);
----------------
jansvoboda11 wrote:

Is there a reason not to sink this logic directly into `getOrCreateContentCache()` and maybe use a different key for the lookup map other than `FileEntryRef`?

https://github.com/llvm/llvm-project/pull/189475


More information about the cfe-commits mailing list