Skip to content

Fix the sort function for languages to have "strict weak ordering". #114160

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

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

jimingham
Copy link
Collaborator

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2024

@llvm/pr-subscribers-lldb

Author: None (jimingham)

Changes

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.


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

1 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectType.cpp (+1)
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)

Copy link

github-actions bot commented Oct 30, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@jimingham jimingham merged commit 9cd30b1 into llvm:main Oct 30, 2024
7 checks passed
@jimingham jimingham deleted the strict-weak-ordering branch October 30, 2024 16:26
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…lvm#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.
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