https://github.com/localspook updated 
https://github.com/llvm/llvm-project/pull/174237

>From d4b84182ffb5346df7a7d78d2df43a0c54f6d205 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <[email protected]>
Date: Fri, 2 Jan 2026 07:49:33 -0800
Subject: [PATCH 1/2] [clang-tidy] Speed up deduplicating warnings from alias
 checks

---
 .../ClangTidyDiagnosticConsumer.cpp           | 45 +++++++++----------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 0355eccc397e5..5718b3f602da9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -783,38 +783,33 @@ std::vector<ClangTidyError> 
ClangTidyDiagnosticConsumer::take() {
   return std::move(Errors);
 }
 
-namespace {
-struct LessClangTidyErrorWithoutDiagnosticName {
-  bool operator()(const ClangTidyError *LHS, const ClangTidyError *RHS) const {
-    const tooling::DiagnosticMessage &M1 = LHS->Message;
-    const tooling::DiagnosticMessage &M2 = RHS->Message;
-
-    return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
-           std::tie(M2.FilePath, M2.FileOffset, M2.Message);
-  }
-};
-} // end anonymous namespace
-
 void ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() 
{
-  using UniqueErrorSet =
-      std::set<ClangTidyError *, LessClangTidyErrorWithoutDiagnosticName>;
-  UniqueErrorSet UniqueErrors;
+  if (Errors.size() <= 1)
+    return;
+
+  static constexpr auto Projection = [](const ClangTidyError &E) {
+    const tooling::DiagnosticMessage &M = E.Message;
+    return std::tie(M.FilePath, M.FileOffset, M.Message);
+  };
 
-  auto IT = Errors.begin();
-  while (IT != Errors.end()) {
-    ClangTidyError &Error = *IT;
-    const std::pair<UniqueErrorSet::iterator, bool> Inserted =
-        UniqueErrors.insert(&Error);
+  // This orders any duplicates into consecutive runs.
+  llvm::stable_sort(Errors,
+                    [](const ClangTidyError &LHS, const ClangTidyError &RHS) {
+                      return Projection(LHS) < Projection(RHS);
+                    });
 
+  auto LastUniqueError = Errors.begin();
+  for (ClangTidyError &Error : llvm::drop_begin(Errors, 1)) {
+    ClangTidyError &ExistingError = *LastUniqueError;
     // Unique error, we keep it and move along.
-    if (Inserted.second) {
-      ++IT;
+    if (Projection(Error) != Projection(ExistingError)) {
+      ++LastUniqueError;
+      *LastUniqueError = std::move(Error);
     } else {
-      ClangTidyError &ExistingError = **Inserted.first;
       const llvm::StringMap<tooling::Replacements> &CandidateFix =
           Error.Message.Fix;
       const llvm::StringMap<tooling::Replacements> &ExistingFix =
-          (*Inserted.first)->Message.Fix;
+          ExistingError.Message.Fix;
 
       if (CandidateFix != ExistingFix) {
         // In case of a conflict, don't suggest any fix-it.
@@ -833,7 +828,7 @@ void 
ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() {
 
       // Since it is the same error, we should take it as alias and remove it.
       
ExistingError.EnabledDiagnosticAliases.emplace_back(Error.DiagnosticName);
-      IT = Errors.erase(IT);
     }
   }
+  Errors.erase(LastUniqueError + 1, Errors.end());
 }

>From ed8d0aff0cbfe8348fd27bc12914a2073c1aa6f9 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <[email protected]>
Date: Fri, 2 Jan 2026 12:06:14 -0800
Subject: [PATCH 2/2] TMP

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.cpp  | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 5718b3f602da9..c959e432ff1ee 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -760,9 +760,9 @@ struct LessClangTidyError {
     const tooling::DiagnosticMessage &M1 = LHS.Message;
     const tooling::DiagnosticMessage &M2 = RHS.Message;
 
-    return std::tie(M1.FilePath, M1.FileOffset, LHS.DiagnosticName,
-                    M1.Message) <
-           std::tie(M2.FilePath, M2.FileOffset, RHS.DiagnosticName, 
M2.Message);
+    return std::tie(M1.FilePath, M1.FileOffset, M1.Message,
+                    LHS.DiagnosticName) <
+           std::tie(M2.FilePath, M2.FileOffset, M2.Message, 
RHS.DiagnosticName);
   }
 };
 struct EqualClangTidyError {
@@ -792,20 +792,15 @@ void 
ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() {
     return std::tie(M.FilePath, M.FileOffset, M.Message);
   };
 
-  // This orders any duplicates into consecutive runs.
-  llvm::stable_sort(Errors,
-                    [](const ClangTidyError &LHS, const ClangTidyError &RHS) {
-                      return Projection(LHS) < Projection(RHS);
-                    });
-
   auto LastUniqueError = Errors.begin();
   for (ClangTidyError &Error : llvm::drop_begin(Errors, 1)) {
     ClangTidyError &ExistingError = *LastUniqueError;
     // Unique error, we keep it and move along.
     if (Projection(Error) != Projection(ExistingError)) {
       ++LastUniqueError;
-      *LastUniqueError = std::move(Error);
-    } else {
+      if (&*LastUniqueError != &Error)
+        *LastUniqueError = std::move(Error);
+    } else if (Error.DiagnosticName != ExistingError.DiagnosticName) {
       const llvm::StringMap<tooling::Replacements> &CandidateFix =
           Error.Message.Fix;
       const llvm::StringMap<tooling::Replacements> &ExistingFix =

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to