[Lldb-commits] [lldb] 8b2dff9 - [lldb] Fix a positioning bug in diagnostics output (#116711)

via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 19 08:58:55 PST 2024


Author: Adrian Prantl
Date: 2024-11-19T08:58:49-08:00
New Revision: 8b2dff960d9d987c583c3a6d5729f01d101dc401

URL: https://github.com/llvm/llvm-project/commit/8b2dff960d9d987c583c3a6d5729f01d101dc401
DIFF: https://github.com/llvm/llvm-project/commit/8b2dff960d9d987c583c3a6d5729f01d101dc401.diff

LOG: [lldb] Fix a positioning bug in diagnostics output (#116711)

The old code did not take the indentation into account.

Added: 
    

Modified: 
    lldb/source/Utility/DiagnosticsRendering.cpp
    lldb/unittests/Utility/DiagnosticsRenderingTest.cpp

Removed: 
    


################################################################################
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