Skip to content

[lldb] Fix the sorting function for diagnostics #113220

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 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lldb/source/Utility/DiagnosticsRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ void RenderDiagnosticDetails(Stream &stream,

// Sort the diagnostics.
auto sort = [](auto &ds) {
llvm::sort(ds.begin(), ds.end(), [](auto &d1, auto &d2) {
std::stable_sort(ds.begin(), ds.end(), [](auto &d1, auto &d2) {
auto l1 = d1.source_location.value_or(DiagnosticDetail::SourceLocation{});
auto l2 = d2.source_location.value_or(DiagnosticDetail::SourceLocation{});
return std::pair(l1.line, l2.column) < std::pair(l1.line, l2.column);
return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);
});
};
sort(remaining_details);
Expand Down
10 changes: 7 additions & 3 deletions lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ TEST_F(ErrorDisplayTest, RenderStatus) {
std::string result =
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
ASSERT_LT(StringRef(result).find("Y"), StringRef(result).find("X"));
// Unintuitively the later diagnostic appears first in the string:
// ^ ^
// | second
// first
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
}
{
// Test that diagnostics in reverse order are emitted correctly.
SourceLocation loc1 = {FileSpec{"a.c"}, 2, 10, 0, false, true};
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 10, 0, false, true};
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 20, 0, false, true};
std::string result =
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
ASSERT_LT(StringRef(result).find("Y"), StringRef(result).find("X"));
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
}
{
// Test that range diagnostics are emitted correctly.
Expand Down
Loading