llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

<details>
<summary>Changes</summary>

The old code did not take the indentation into account.

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


2 Files Affected:

- (modified) lldb/source/Utility/DiagnosticsRendering.cpp (+2-2) 
- (modified) lldb/unittests/Utility/DiagnosticsRenderingTest.cpp (+19-1) 


``````````diff
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");
+  }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/116711
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to