[clang-tools-extra] [Clangd] Sanitize path before recording into IncludeStructure during buildPreamble (PR #70798)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 06:28:01 PDT 2023


https://github.com/Maddobun updated https://github.com/llvm/llvm-project/pull/70798

>From f2dd9b98a6dab3bf6c1cc06df8262313d62ecbe0 Mon Sep 17 00:00:00 2001
From: Leo Zhu <yifu.zhu at microchip.com>
Date: Tue, 31 Oct 2023 09:27:47 -0400
Subject: [PATCH] Sanitize path before recording into IncludeStructure
 addresses https://github.com/clangd/clangd/issues/1800

---
 clang-tools-extra/clangd/Headers.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 6005069be01160d..627ea86ee139db2 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -56,7 +56,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
       Inc.Written =
           (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
       Inc.Resolved = std::string(
-          File ? getCanonicalPath(*File, SM.getFileManager()).value_or("")
+          File ? maybeCaseFoldPath(getCanonicalPath(*File, SM.getFileManager()).value_or(""))
                : "");
       Inc.HashOffset = SM.getFileOffset(HashLoc);
       Inc.HashLine =
@@ -208,7 +208,7 @@ IncludeStructure::HeaderID IncludeStructure::getOrCreateID(FileEntryRef Entry) {
   // Main file's FileEntry was not known at IncludeStructure creation time.
   if (&Entry.getFileEntry() == MainFileEntry) {
     if (RealPathNames.front().empty())
-      RealPathNames.front() = MainFileEntry->tryGetRealPathName().str();
+      RealPathNames.front() = maybeCaseFoldPath(MainFileEntry->tryGetRealPathName().str());
     return MainFileID;
   }
   auto R = UIDToIndex.try_emplace(
@@ -219,7 +219,7 @@ IncludeStructure::HeaderID IncludeStructure::getOrCreateID(FileEntryRef Entry) {
   IncludeStructure::HeaderID Result = R.first->getSecond();
   std::string &RealPathName = RealPathNames[static_cast<unsigned>(Result)];
   if (RealPathName.empty())
-    RealPathName = Entry.getFileEntry().tryGetRealPathName().str();
+    RealPathName = maybeCaseFoldPath(Entry.getFileEntry().tryGetRealPathName().str());
   return Result;
 }
 



More information about the cfe-commits mailing list