[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 00:05:21 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: clang, cjdb, aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We should preserve empty lines in output snippets.


Repository:
  rG LLVM Github Monorepo

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
@@ -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.525032.patch
Type: text/x-patch
Size: 1227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/95d3d575/attachment-0001.bin>


More information about the cfe-commits mailing list