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

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


================
@@ -542,14 +580,27 @@ 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 (referencesDistinctFilePaths(getFileManager(), *IR.OrigEntry,
+                                    SourceFile)) {
+      Cache = cloneContentCache(ContentCacheAlloc, IR);
+      Cache->OrigEntry = SourceFile;
+      FileIDContentCaches.push_back(Cache);
+    } else {
+      Filename = IR.OrigEntry->getName();
----------------
jansvoboda11 wrote:

I'd rather not special-case Windows path separators here.

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


More information about the cfe-commits mailing list