[clang-tools-extra] [NFC] [clangd] [C++20] [Modules] Fix false duplicate module warning for equivalent paths (PR #199343)

via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 23:28:04 PDT 2026


https://github.com/Li-Zheng-Rong updated https://github.com/llvm/llvm-project/pull/199343

>From 6bd6ddaed2e0bb60db349a1f4d86b2c8eacf4dd7 Mon Sep 17 00:00:00 2001
From: Li-Zheng-Rong <2508120225 at hhu.edu.cn>
Date: Sat, 23 May 2026 18:47:44 +0800
Subject: [PATCH] [NFC] [clangd] [C++20] [Modules] Fix false duplicate module
 warning for equivalent paths

When checking for multiple source files declaring the same module,
the comparison used raw string equality on file paths. This causes
false positives when the same file is represented by different but
equivalent path strings.

Use pathEqual(normalizePath(...), normalizePath(...)) instead to
compare canonical paths, consistent with how clangd handles path
comparisons elsewhere.
---
 clang-tools-extra/clangd/ProjectModules.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/ProjectModules.cpp b/clang-tools-extra/clangd/ProjectModules.cpp
index d3727171bff12..33cbc715e9659 100644
--- a/clang-tools-extra/clangd/ProjectModules.cpp
+++ b/clang-tools-extra/clangd/ProjectModules.cpp
@@ -247,7 +247,8 @@ ModuleDependencyScanner::scan(PathRef FilePath,
     auto [Iter, Inserted] = ModuleNameToSource.try_emplace(
         ScanningResult->Provides->ModuleName, FilePath);
 
-    if (!Inserted && Iter->second != FilePath) {
+    if (!Inserted &&
+        !pathEqual(normalizePath(Iter->second), normalizePath(FilePath))) {
       elog("Detected multiple source files ({0}, {1}) declaring the same "
            "module: '{2}'. "
            "Now clangd may find the wrong source in such case.",



More information about the cfe-commits mailing list