Skip to content

[lldb] Use llvm::stable_sort (NFC) #141352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/141352.diff

6 Files Affected:

  • (modified) lldb/include/lldb/Utility/RangeMap.h (+9-9)
  • (modified) lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (+1-2)
  • (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+4-5)
  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+3-4)
  • (modified) lldb/source/Symbol/Symtab.cpp (+1-1)
  • (modified) lldb/source/Utility/DiagnosticsRendering.cpp (+1-1)
diff --git a/lldb/include/lldb/Utility/RangeMap.h b/lldb/include/lldb/Utility/RangeMap.h
index 2f7711c1eb11e..e701ae1ba96c8 100644
--- a/lldb/include/lldb/Utility/RangeMap.h
+++ b/lldb/include/lldb/Utility/RangeMap.h
@@ -216,7 +216,7 @@ template <typename B, typename S, unsigned N = 0> class RangeVector {
 
   void Sort() {
     if (m_entries.size() > 1)
-      std::stable_sort(m_entries.begin(), m_entries.end());
+      llvm::stable_sort(m_entries);
   }
 
 #ifdef ASSERT_RANGEMAP_ARE_SORTED
@@ -484,14 +484,14 @@ class RangeDataVector {
 
   void Sort() {
     if (m_entries.size() > 1)
-      std::stable_sort(m_entries.begin(), m_entries.end(),
-                       [&compare = m_compare](const Entry &a, const Entry &b) {
-                         if (a.base != b.base)
-                           return a.base < b.base;
-                         if (a.size != b.size)
-                           return a.size < b.size;
-                         return compare(a.data, b.data);
-                       });
+      llvm::stable_sort(m_entries,
+                        [&compare = m_compare](const Entry &a, const Entry &b) {
+                          if (a.base != b.base)
+                            return a.base < b.base;
+                          if (a.size != b.size)
+                            return a.size < b.size;
+                          return compare(a.data, b.data);
+                        });
     if (!m_entries.empty())
       ComputeUpperBounds(0, m_entries.size());
   }
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 609968bf0bde2..389339a1bc622 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -919,8 +919,7 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list,
     uint32_t idx = symtab.AddSymbol(symbol);
     export_list.push_back(std::make_pair(function_rva, idx));
   }
-  std::stable_sort(export_list.begin(), export_list.end(),
-                   RVASymbolListCompareRVA);
+  llvm::stable_sort(export_list, RVASymbolListCompareRVA);
   return export_list;
 }
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 709d09fc887bc..420c84b496d15 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2758,11 +2758,10 @@ Status ProcessGDBRemote::WriteObjectFile(
   Status error;
   // Sort the entries by address because some writes, like those to flash
   // memory, must happen in order of increasing address.
-  std::stable_sort(
-      std::begin(entries), std::end(entries),
-      [](const ObjectFile::LoadableData a, const ObjectFile::LoadableData b) {
-        return a.Dest < b.Dest;
-      });
+  llvm::stable_sort(entries, [](const ObjectFile::LoadableData a,
+                                const ObjectFile::LoadableData b) {
+    return a.Dest < b.Dest;
+  });
   m_allow_flash_writes = true;
   error = Process::WriteObjectFile(entries);
   if (error.Success())
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 150c08ff353ea..8c19d5be76bcf 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -8631,10 +8631,9 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
   // Sort in reverse order of the number of the population count,  so that in
   // `enum {A, B, ALL = A|B }` we visit ALL first. Use a stable sort so that
   // A | C where A is declared before C is displayed in this order.
-  std::stable_sort(values.begin(), values.end(),
-                   [](const auto &a, const auto &b) {
-                     return llvm::popcount(a.first) > llvm::popcount(b.first);
-                   });
+  llvm::stable_sort(values, [](const auto &a, const auto &b) {
+    return llvm::popcount(a.first) > llvm::popcount(b.first);
+  });
 
   for (const auto &val : values) {
     if ((remaining_value & val.first) != val.first)
diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 9a3e8476fa356..970f6c474e375 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -638,7 +638,7 @@ void Symtab::SortSymbolIndexesByValue(std::vector<uint32_t> &indexes,
   std::vector<lldb::addr_t> addr_cache(m_symbols.size(), LLDB_INVALID_ADDRESS);
 
   SymbolIndexComparator comparator(m_symbols, addr_cache);
-  std::stable_sort(indexes.begin(), indexes.end(), comparator);
+  llvm::stable_sort(indexes, comparator);
 
   // Remove any duplicates if requested
   if (remove_duplicates) {
diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp
index 6f276a81fbc8e..8c21e661ce764 100644
--- a/lldb/source/Utility/DiagnosticsRendering.cpp
+++ b/lldb/source/Utility/DiagnosticsRendering.cpp
@@ -140,7 +140,7 @@ void RenderDiagnosticDetails(Stream &stream,
 
   // Sort the diagnostics.
   auto sort = [](std::vector<DiagnosticDetail> &ds) {
-    std::stable_sort(ds.begin(), ds.end(), [](auto &d1, auto &d2) {
+    llvm::stable_sort(ds, [](auto &d1, auto &d2) {
       auto l1 = d1.source_location.value_or(DiagnosticDetail::SourceLocation{});
       auto l2 = d2.source_location.value_or(DiagnosticDetail::SourceLocation{});
       return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);

@kazutakahirata kazutakahirata merged commit 4788d5f into llvm:main May 24, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250524_llvm_stable_sort_lldb branch May 24, 2025 16:38
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants