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

Addresses https://github.com/clangd/clangd/issues/1800, where mismatching drive 
letter case can cause command inference for header files to fail on windows.

>From 65c1b38c4eb83469794e53328caed492e956a728 Mon Sep 17 00:00:00 2001
From: Leo Zhu <yifu....@microchip.com>
Date: Mon, 30 Oct 2023 16:50:57 -0400
Subject: [PATCH] Sanitize path before recording into IncludeStructure
 addresses https://github.com/clangd/clangd/issues/1800

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

diff --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 6005069be01160d..5af7abd71ae1097 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -9,6 +9,7 @@
 #include "Headers.h"
 #include "Preamble.h"
 #include "SourceCode.h"
+#include "support/Logger.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -56,7 +57,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 +209,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 +220,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;
 }
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to