[Lldb-commits] [lldb] [lldb] Fix a positioning bug in diagnostics output (PR #116711)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 18 15:26:31 PST 2024
https://github.com/adrian-prantl created https://github.com/llvm/llvm-project/pull/116711
The old code did not take the indentation into account.
>From cd312045308032582539fe8302c34cab265aaa5a Mon Sep 17 00:00:00 2001
From: Adrian Prantl <aprantl at apple.com>
Date: Mon, 18 Nov 2024 15:22:24 -0800
Subject: [PATCH] [lldb] Fix a positioning bug in diagnostics output
The old code did not take the indentation into account.
---
lldb/source/Utility/DiagnosticsRendering.cpp | 4 ++--
.../Utility/DiagnosticsRenderingTest.cpp | 20 ++++++++++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp
index 208733ffc86853..dfc47ac460ac9f 100644
--- a/lldb/source/Utility/DiagnosticsRendering.cpp
+++ b/lldb/source/Utility/DiagnosticsRendering.cpp
@@ -121,10 +121,10 @@ void RenderDiagnosticDetails(Stream &stream,
continue;
stream << std::string(loc.column - x_pos, ' ') << cursor;
- ++x_pos;
+ x_pos = loc.column + 1;
for (unsigned i = 0; i + 1 < loc.length; ++i) {
stream << underline;
- ++x_pos;
+ x_pos += 1;
}
}
}
diff --git a/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp b/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
index ad2ebf7ffe1e2f..1187f3f65f27fd 100644
--- a/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
+++ b/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
@@ -74,9 +74,27 @@ TEST_F(ErrorDisplayTest, RenderStatus) {
auto line2 = lines.first;
lines = lines.second.split('\n');
auto line3 = lines.first;
- // 1234567
+ // 1234567
ASSERT_EQ(line1, "^~~ ^~~");
ASSERT_EQ(line2, "| error: Y");
ASSERT_EQ(line3, "error: X");
}
+ {
+ // Test diagnostics on the same line are emitted correctly.
+ SourceLocation loc1 = {FileSpec{"a.c"}, 1, 2, 0, false, true};
+ SourceLocation loc2 = {FileSpec{"a.c"}, 1, 6, 0, false, true};
+ std::string result =
+ Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"},
+ DiagnosticDetail{loc2, eSeverityError, "Y", "Y"}});
+ auto lines = StringRef(result).split('\n');
+ auto line1 = lines.first;
+ lines = lines.second.split('\n');
+ auto line2 = lines.first;
+ lines = lines.second.split('\n');
+ auto line3 = lines.first;
+ // 1234567
+ ASSERT_EQ(line1, " ^ ^");
+ ASSERT_EQ(line2, " | error: Y");
+ ASSERT_EQ(line3, " error: X");
+ }
}
More information about the lldb-commits
mailing list