[PATCH] D151301: [clang][Diagnostics] Print empty lines in multiline snippets

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 01:03:05 PDT 2023


tbaeder updated this revision to Diff 525050.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151301/new/

https://reviews.llvm.org/D151301

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Misc/diag-style.cpp


Index: clang/test/Misc/diag-style.cpp
===================================================================
--- /dev/null
+++ clang/test/Misc/diag-style.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
+
+/// empty lines in multi-line diagnostic snippets are preserved.
+static_assert(false &&
+
+              true, "");
+// CHECK: static assertion failed
+// CHECK-NEXT: {{^}}    4 | static_assert(false &&{{$}}
+// CHECK-NEXT: {{^}}      |               ^~~~~~~~{{$}}
+// CHECK-NEXT: {{^}}    5 | {{$}}
+// CHECK-NEXT: {{^}}    6 |               true, "");{{$}}
+// CHECK-NEXT: {{^}}      |               ~~~~{{$}}
Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1243,7 +1243,7 @@
     // to produce easily machine parsable output.  Add a space before the
     // source line and the caret to make it trivial to tell the main diagnostic
     // line from what the user is intended to see.
-    if (DiagOpts->ShowSourceRanges) {
+    if (DiagOpts->ShowSourceRanges && !SourceLine.empty()) {
       SourceLine = ' ' + SourceLine;
       CaretLine = ' ' + CaretLine;
     }
@@ -1280,9 +1280,6 @@
 void TextDiagnostic::emitSnippet(StringRef SourceLine,
                                  unsigned MaxLineNoDisplayWidth,
                                  unsigned LineNo) {
-  if (SourceLine.empty())
-    return;
-
   // Emit line number.
   if (MaxLineNoDisplayWidth > 0) {
     unsigned LineNoDisplayWidth = getNumDisplayWidth(LineNo);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151301.525050.patch
Type: text/x-patch
Size: 1639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/73d2debb/attachment-0001.bin>


More information about the cfe-commits mailing list