[Lldb-commits] [lldb] Fix the sort function for languages to have "strict weak ordering". (PR #114160)

via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 29 17:22:49 PDT 2024


https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/114160

>From 237cb04100fd35df22b4e743c575681f31b54970 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Tue, 29 Oct 2024 17:11:43 -0700
Subject: [PATCH 1/2] Fix the sort function for languages to have "strict weak
 ordering".

If you build libstdc++ with "debug" strictness, the test TestTypeLookup.py
will assert.  That's because we're calling llvm::sort (which redirects to
std::sort) with a function that doesn't obey strict weak ordering.

The error was that when the two languages were equal, we're sometimes
returning `true` but strict weak ordering requires that always be false.

This patch just makes the function behave properly.
---
 lldb/source/Commands/CommandObjectType.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index f9786529bcdb1c..b5230216bb221a 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -2649,6 +2649,7 @@ class CommandObjectTypeLookup : public CommandObjectRaw {
                 return false;
               LanguageType lt1 = lang1->GetLanguageType();
               LanguageType lt2 = lang2->GetLanguageType();
+              if (lt1 == lt2) return false;
               if (lt1 == guessed_language)
                 return true; // make the selected frame's language come first
               if (lt2 == guessed_language)

>From a29750070153ad858140ce0dba13357b5d998044 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Tue, 29 Oct 2024 17:22:31 -0700
Subject: [PATCH 2/2] clang-format

---
 lldb/source/Commands/CommandObjectType.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index b5230216bb221a..e4c6e374446e82 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -2649,7 +2649,8 @@ class CommandObjectTypeLookup : public CommandObjectRaw {
                 return false;
               LanguageType lt1 = lang1->GetLanguageType();
               LanguageType lt2 = lang2->GetLanguageType();
-              if (lt1 == lt2) return false;
+              if (lt1 == lt2)
+                return false;
               if (lt1 == guessed_language)
                 return true; // make the selected frame's language come first
               if (lt2 == guessed_language)



More information about the lldb-commits mailing list