[clang] clang: normalise directory cache keys consistently in `FileManager` (PR #181306)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 18 12:30:24 PST 2026


================
@@ -38,6 +38,27 @@ using namespace clang;
 
 #define DEBUG_TYPE "file-search"
 
+static void normalizeCacheKey(StringRef &Path,
+                              std::optional<std::string> &Storage) {
+  using namespace llvm::sys::path;
+
+  // Drop trailing separators for non-root paths so that cache keys and `stat`
+  // queries use a single spelling. Keep root paths (`/`, `[A-Z]:\`) unchanged.
+  if (Path.size() > 1 && root_path(Path) != Path && is_separator(Path.back()))
+    Path = Path.drop_back();
+
+  // A bare drive path like "[A-Z:" is drive-relative (current directory on the
----------------
cor3ntin wrote:

```suggestion
  // A bare drive path like "[A-Z]:" is drive-relative (current directory on the
```

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


More information about the cfe-commits mailing list