Skip to content

Commit 74e1554

Browse files
[lldb] Fix the sorting function for diagnostics (#113220)
1 parent 9de0566 commit 74e1554

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lldb/source/Utility/DiagnosticsRendering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ void RenderDiagnosticDetails(Stream &stream,
9999

100100
// Sort the diagnostics.
101101
auto sort = [](auto &ds) {
102-
llvm::sort(ds.begin(), ds.end(), [](auto &d1, auto &d2) {
102+
std::stable_sort(ds.begin(), ds.end(), [](auto &d1, auto &d2) {
103103
auto l1 = d1.source_location.value_or(DiagnosticDetail::SourceLocation{});
104104
auto l2 = d2.source_location.value_or(DiagnosticDetail::SourceLocation{});
105-
return std::pair(l1.line, l2.column) < std::pair(l1.line, l2.column);
105+
return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);
106106
});
107107
};
108108
sort(remaining_details);

lldb/unittests/Utility/DiagnosticsRenderingTest.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ TEST_F(ErrorDisplayTest, RenderStatus) {
4646
std::string result =
4747
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
4848
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
49-
ASSERT_LT(StringRef(result).find("Y"), StringRef(result).find("X"));
49+
// Unintuitively the later diagnostic appears first in the string:
50+
// ^ ^
51+
// | second
52+
// first
53+
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
5054
}
5155
{
5256
// Test that diagnostics in reverse order are emitted correctly.
53-
SourceLocation loc1 = {FileSpec{"a.c"}, 2, 10, 0, false, true};
57+
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 10, 0, false, true};
5458
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 20, 0, false, true};
5559
std::string result =
5660
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
5761
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
58-
ASSERT_LT(StringRef(result).find("Y"), StringRef(result).find("X"));
62+
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
5963
}
6064
{
6165
// Test that range diagnostics are emitted correctly.

0 commit comments

Comments
 (0)