[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:16:30 PDT 2024


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

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.

>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] 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)



More information about the lldb-commits mailing list