Skip to content

[lldb] Fix a positioning bug in diagnostics output #116711

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
Nov 19, 2024

Conversation

adrian-prantl
Copy link
Collaborator

The old code did not take the indentation into account.

The old code did not take the indentation into account.
@llvmbot
Copy link
Member

llvmbot commented Nov 18, 2024

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

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

Copy link
Contributor

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@adrian-prantl adrian-prantl merged commit 8b2dff9 into llvm:main Nov 19, 2024
9 checks passed
adrian-prantl added a commit that referenced this pull request Nov 19, 2024
…16727)

depends on #116711

[lldb] Improve rendering of inline diagnostics on the same column by
fixing the indentation and printing these annotations in the original
order.

Before

    a+b+c;
    ^ ^ ^
    | | error: 3
    | |note: 2b
    | error: 2a
    error: 1

After

    a+b+c;
    ^ ^ ^
    | | error: 3
    | error: 2a
    | note: 2b
    error: 1
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Nov 19, 2024
The old code did not take the indentation into account.

(cherry picked from commit 8b2dff9)
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Nov 19, 2024
…vm#116727)

depends on llvm#116711

[lldb] Improve rendering of inline diagnostics on the same column by
fixing the indentation and printing these annotations in the original
order.

Before

    a+b+c;
    ^ ^ ^
    | | error: 3
    | |note: 2b
    | error: 2a
    error: 1

After

    a+b+c;
    ^ ^ ^
    | | error: 3
    | error: 2a
    | note: 2b
    error: 1

(cherry picked from commit 6b4f675)
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Nov 19, 2024
…23-lldb-Fix-a-positioning-bug-in-diagnostics-output-116711

[Cherry-pick into stable/20240723] [lldb] Fix a positioning bug in diagnostics output (llvm#116711)
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Dec 5, 2024
The old code did not take the indentation into account.

(cherry picked from commit 8b2dff9)
(cherry picked from commit 3703aad)
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Dec 5, 2024
…vm#116727)

depends on llvm#116711

[lldb] Improve rendering of inline diagnostics on the same column by
fixing the indentation and printing these annotations in the original
order.

Before

    a+b+c;
    ^ ^ ^
    | | error: 3
    | |note: 2b
    | error: 2a
    error: 1

After

    a+b+c;
    ^ ^ ^
    | | error: 3
    | error: 2a
    | note: 2b
    error: 1

(cherry picked from commit 6b4f675)
(cherry picked from commit 7e80550)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants