[llvm-branch-commits] [llvm] [FileCheck][NFC] Introduce Mid/Tail to -dump-input MarkerStyle (PR #196799)
https://github.com/jdenny-ornl created
https://github.com/llvm/llvm-project/pull/196799
Normally, Head is something like `^` and Mid and Tail are just `~`. However,
the upcoming search range markers will have Head as `{`, Mid as ` `, and Tail
as `}`. This patch separately introduces the Mid/Tail support to facilitate
the review, but it is not used for anything yet here.
This PR is stacked on PR #196797.
>From 090410b25163bb975f6943aa718c5c584df906e3 Mon Sep 17 00:00:00 2001
From: "Joel E. Denny"
Date: Sat, 9 May 2026 22:47:50 -0400
Subject: [PATCH] [FileCheck][NFC] Introduce Mid/Tail to -dump-input
MarkerStyle
Normally, Head is something like `^` and Mid and Tail are just `~`.
However, the upcoming search range markers will have Head as `{`, Mid
as ` `, and Tail as `}`. This patch separately introduces the
Mid/Tail support to facilitate the review, but it is not used for
anything yet here.
---
llvm/utils/FileCheck/FileCheck.cpp | 58 +++---
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/llvm/utils/FileCheck/FileCheck.cpp
b/llvm/utils/FileCheck/FileCheck.cpp
index 761030c6886bf..a33acb926e91f 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -184,8 +184,13 @@ static void DumpCommandLine(int argc, char **argv) {
}
struct MarkerStyle {
- /// The starting char (before tildes) for marking the line.
- char Lead;
+ /// The first char for marking the input line.
+ char Head;
+ /// Every character for marking the input line between \c Head and \c Tail.
+ /// Normally it is a tilde.
+ char Mid;
+ /// The final char for marking the input line. Normally it is a tilde.
+ char Tail;
/// What color to use for this annotation.
raw_ostream::Colors Color;
/// A note to follow the marker, or empty string if none.
@@ -207,7 +212,12 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
// used instead.
MarkerStyle Res;
bool IsError = Diag.isError() || Diag.getMatchResultDiag().isError();
- Res.Lead = !Diag.getMatchRange() ? ' ' : IsError ? '!' : '^';
+ if (Diag.getMatchRange()) {
+Res.Head = IsError ? '!' : '^';
+Res.Mid = Res.Tail = '~';
+ } else {
+Res.Head = Res.Mid = Res.Tail = ' ';
+ }
Res.Color = IsError ? raw_ostream::RED : raw_ostream::GREEN;
Res.FiltersAsError = IsError;
@@ -224,14 +234,15 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
Res.Note = "match on wrong line";
break;
case MatchFoundDiag::Discarded:
- Res.Lead = '!'; // Not an error, but not a successful match either.
+ Res.Head = '!'; // Not an error, but not a successful match either.
Res.Color = raw_ostream::CYAN;
Res.Note = "discard: overlaps earlier match";
break;
}
break;
case FileCheckDiag::MatchNoneDiag:
-Res.Lead = 'X';
+Res.Head = 'X';
+Res.Mid = Res.Tail = '~';
switch (cast(Diag).getStatus()) {
case MatchNoneDiag::Success:
break;
@@ -244,7 +255,7 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
}
break;
case FileCheckDiag::MatchFuzzyDiag:
-Res.Lead = '?';
+Res.Head = '?';
Res.Color = raw_ostream::MAGENTA;
Res.Note = "possible intended match";
break;
@@ -359,8 +370,8 @@ struct InputAnnotation {
/// !IsFirstLine.
unsigned InputLine;
/// The column range (one-origin indexing, open end) in which to mark the
- /// input line. If InputEndCol is UINT_MAX, treat it as the last column
- /// before the newline.
+ /// input line. If \c InputEndCol is \c UINT_MAX, the rest of the input line
+ /// should be marked.
unsigned InputStartCol, InputEndCol;
/// The marker to use.
MarkerStyle Marker;
@@ -537,6 +548,13 @@ buildInputAnnotations(const SourceMgr &SM, unsigned
CheckFileBufferID,
SM.getLineAndColumn(InputRange.Start);
auto [InputEndLine, InputEndCol] = SM.getLineAndColumn(InputRange.End);
+// If a range ends before the first column on a line, then it has no
+// characters on that line, so there is nothing to render there.
+if (InputStartLine < InputEndLine && InputEndCol == 1) {
+ --InputEndLine;
+ InputEndCol = UINT_MAX;
+}
+
// Compute the marker location, and break annotation into multiple
// annotations if it spans multiple lines.
A.IsFirstLine = true;
@@ -552,25 +570,21 @@ buildInputAnnotations(const SourceMgr &SM, unsigned
CheckFileBufferID,
assert(InputStartLine < InputEndLine &&
"expected input range not to be inverted");
A.InputEndCol = UINT_MAX;
+ char MarkerTail = A.Marker.Tail;
+ A.Marker.Tail = A.Marker.Mid;
Annotations.push_back(A);
for (unsigned L = InputStartLine + 1, E = InputEndLine; L <= E; ++L) {
-// If a range ends before the first column on a line, then it has no
-// characters on that line, so there's nothing to render.
-if (InputEndCol == 1 && L == E)
- break;
[llvm-branch-commits] [llvm] [FileCheck][NFC] Introduce Mid/Tail to -dump-input MarkerStyle (PR #196799)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-testing-tools
Author: Joel E. Denny (jdenny-ornl)
Changes
Normally, Head is something like `^` and Mid and Tail are just `~`. However,
the upcoming search range markers will have Head as `{`, Mid as ` `, and Tail
as `}`. This patch separately introduces the Mid/Tail support to facilitate
the review, but it is not used for anything yet here.
This PR is stacked on PR #196797.
---
Full diff: https://github.com/llvm/llvm-project/pull/196799.diff
1 Files Affected:
- (modified) llvm/utils/FileCheck/FileCheck.cpp (+38-20)
``diff
diff --git a/llvm/utils/FileCheck/FileCheck.cpp
b/llvm/utils/FileCheck/FileCheck.cpp
index 761030c6886bf..a33acb926e91f 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -184,8 +184,13 @@ static void DumpCommandLine(int argc, char **argv) {
}
struct MarkerStyle {
- /// The starting char (before tildes) for marking the line.
- char Lead;
+ /// The first char for marking the input line.
+ char Head;
+ /// Every character for marking the input line between \c Head and \c Tail.
+ /// Normally it is a tilde.
+ char Mid;
+ /// The final char for marking the input line. Normally it is a tilde.
+ char Tail;
/// What color to use for this annotation.
raw_ostream::Colors Color;
/// A note to follow the marker, or empty string if none.
@@ -207,7 +212,12 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
// used instead.
MarkerStyle Res;
bool IsError = Diag.isError() || Diag.getMatchResultDiag().isError();
- Res.Lead = !Diag.getMatchRange() ? ' ' : IsError ? '!' : '^';
+ if (Diag.getMatchRange()) {
+Res.Head = IsError ? '!' : '^';
+Res.Mid = Res.Tail = '~';
+ } else {
+Res.Head = Res.Mid = Res.Tail = ' ';
+ }
Res.Color = IsError ? raw_ostream::RED : raw_ostream::GREEN;
Res.FiltersAsError = IsError;
@@ -224,14 +234,15 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
Res.Note = "match on wrong line";
break;
case MatchFoundDiag::Discarded:
- Res.Lead = '!'; // Not an error, but not a successful match either.
+ Res.Head = '!'; // Not an error, but not a successful match either.
Res.Color = raw_ostream::CYAN;
Res.Note = "discard: overlaps earlier match";
break;
}
break;
case FileCheckDiag::MatchNoneDiag:
-Res.Lead = 'X';
+Res.Head = 'X';
+Res.Mid = Res.Tail = '~';
switch (cast(Diag).getStatus()) {
case MatchNoneDiag::Success:
break;
@@ -244,7 +255,7 @@ static MarkerStyle getMarker(const FileCheckDiag &Diag) {
}
break;
case FileCheckDiag::MatchFuzzyDiag:
-Res.Lead = '?';
+Res.Head = '?';
Res.Color = raw_ostream::MAGENTA;
Res.Note = "possible intended match";
break;
@@ -359,8 +370,8 @@ struct InputAnnotation {
/// !IsFirstLine.
unsigned InputLine;
/// The column range (one-origin indexing, open end) in which to mark the
- /// input line. If InputEndCol is UINT_MAX, treat it as the last column
- /// before the newline.
+ /// input line. If \c InputEndCol is \c UINT_MAX, the rest of the input line
+ /// should be marked.
unsigned InputStartCol, InputEndCol;
/// The marker to use.
MarkerStyle Marker;
@@ -537,6 +548,13 @@ buildInputAnnotations(const SourceMgr &SM, unsigned
CheckFileBufferID,
SM.getLineAndColumn(InputRange.Start);
auto [InputEndLine, InputEndCol] = SM.getLineAndColumn(InputRange.End);
+// If a range ends before the first column on a line, then it has no
+// characters on that line, so there is nothing to render there.
+if (InputStartLine < InputEndLine && InputEndCol == 1) {
+ --InputEndLine;
+ InputEndCol = UINT_MAX;
+}
+
// Compute the marker location, and break annotation into multiple
// annotations if it spans multiple lines.
A.IsFirstLine = true;
@@ -552,25 +570,21 @@ buildInputAnnotations(const SourceMgr &SM, unsigned
CheckFileBufferID,
assert(InputStartLine < InputEndLine &&
"expected input range not to be inverted");
A.InputEndCol = UINT_MAX;
+ char MarkerTail = A.Marker.Tail;
+ A.Marker.Tail = A.Marker.Mid;
Annotations.push_back(A);
for (unsigned L = InputStartLine + 1, E = InputEndLine; L <= E; ++L) {
-// If a range ends before the first column on a line, then it has no
-// characters on that line, so there's nothing to render.
-if (InputEndCol == 1 && L == E)
- break;
InputAnnotation B;
B.LabelIndexGlobal = A.LabelIndexGlobal;
B.Label = A.Label;
B.IsFirstLine = false;
B.InputLine = L;
B.Marker = A.Marker;
-B.Marker.Lead = '~';
+B.Marker.Head = B.Marker.Mid = A.Marker.Mid;
+B.Marker.Tail = L != E ? A.Marker.Mid : MarkerTail;
B.Marker.Note = "";
B.InputStartCol = 1;
-if (L != E)
- B
