[llvm-branch-commits] [llvm] [FileCheck][NFC] Introduce MarkerRange for -dump-input (PR #196800)
https://github.com/jdenny-ornl updated
https://github.com/llvm/llvm-project/pull/196800
>From 1056b809cc934fab24c24b4466e5097b5664c2c4 Mon Sep 17 00:00:00 2001
From: "Joel E. Denny"
Date: Sat, 9 May 2026 23:35:39 -0400
Subject: [PATCH 1/2] [FileCheck][NFC] Introduce MarkerRange for -dump-input
`MarkerRange` makes the computation of marker ranges clearer because
it encapsulates handling of several subtle boundary cases. It will be
used more in a future patch that extends `-dump-input` to present
search ranges for all errors.
---
llvm/utils/FileCheck/FileCheck.cpp | 147 +
1 file changed, 108 insertions(+), 39 deletions(-)
diff --git a/llvm/utils/FileCheck/FileCheck.cpp
b/llvm/utils/FileCheck/FileCheck.cpp
index a33acb926e91f..10f5acf24414c 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -369,10 +369,10 @@ struct InputAnnotation {
/// be different from the starting line of the original diagnostic if
/// !IsFirstLine.
unsigned InputLine;
- /// The column range (one-origin indexing, open end) in which to mark the
- /// input line. If \c InputEndCol is \c UINT_MAX, the rest of the input line
- /// should be marked.
- unsigned InputStartCol, InputEndCol;
+ /// The column range (one-origin indexing, inclusive boundaries) in which to
+ /// mark the input line. If \c InputLastCol is \c UINT_MAX, the rest of the
+ /// input line should be marked.
+ unsigned InputFirstCol, InputLastCol;
/// The marker to use.
MarkerStyle Marker;
/// Whether this annotation represents a good match for an expected pattern.
@@ -472,6 +472,87 @@ class InputAnnotationLabeler {
std::max((std::string::size_type)*LabelWidthGlobal, Label.size());
}
};
+
+/// A range representation with inclusive start and end bounds specifying where
+/// annotation markers are physically drawn in the input dump.
+///
+/// This class encapsulates the conversion of an \c SMRange to lines and
columns
+/// for input annotation markers indicating the same range:
+/// - It handles adjustments to line numbers when a range boundary appears at a
+/// line boundary.
+/// - It avoids related mistakes in determining whether the range is contained
+/// within a single line.
+/// - It avoids the mistake of producing no marker in an input annotation for
an
+/// empty range.
+///
+/// All lines and columns have index-origin one.
+struct MarkerRange {
+public:
+ struct Loc {
+unsigned Line;
+unsigned Col;
+Loc() = default;
+Loc(unsigned Line, unsigned Col) : Line(Line), Col(Col) {}
+Loc(const std::pair &LineAndCol)
+: Line(LineAndCol.first), Col(LineAndCol.second) {}
+ };
+
+private:
+ /// Points to the first character included in the marker range.
+ Loc First;
+ /// Points to the last character included in the marker range.
+ Loc Last;
+ MarkerRange(Loc First, Loc Last) : First(First), Last(Last) {}
+
+public:
+ /// Make an invalid range to be overwritten before being used.
+ MarkerRange() = default;
+ /// Convert \p Range to a \c MarkerRange.
+ ///
+ /// \p Range's start must be inclusive, and its end must be exclusive. It
+ /// specifies the \a logical input range to be depicted by annotation
markers.
+ ///
+ /// The resulting \c MarkerRange's first and last locations are always both
+ /// inclusive. It specifies exactly where markers should be physically
+ /// \a drawn in an input dump. If \p Range is an empty range, then the
+ /// resulting \c MarkerRange is expanded to a single character. This avoids
a
+ /// missing marker for an empty range, but it means the markers for a
+ /// single-character range are indistinguishable from markers for an empty
+ /// range.
+ ///
+ /// Given an \c SMRange representing the range of text "range of text", the
+ /// following example compares how the \c SMRange and a \c MarkerRange
+ /// constructed from it encode their start (s) and end (e) bounds:
+ ///
+ /// foo range of text bar
+ /// seSMRange
+ /// s e MarkerRange
+ ///
+ MarkerRange(const SourceMgr &SM, SMRange Range) {
+First = SM.getLineAndColumn(Range.Start);
+// The SMRange has an exclusive end, but we want an inclusive end.
+if (Range.Start == Range.End) {
+ // Convert the empty range to a one-character range so we do not end up
+ // with a missing marker.
+ Last.Line = First.Line;
+ Last.Col = First.Col;
+} else {
+ // We cannot simply subtract one from the end column number because that
+ // might result in column 0, which does not exist and is thus incorrect
+ // for an inclusive boundary.
+ SMLoc EndLoc = SMLoc::getFromPointer(Range.End.getPointer() - 1);
+ Last = SM.getLineAndColumn(EndLoc);
+}
+ }
+ /// Return true if the marker range is contained on a single line.
+ bool isSingleLine() const { return First.Line == Last.Line; }
+ /// Get the first location incl
[llvm-branch-commits] [llvm] [FileCheck][NFC] Introduce MarkerRange for -dump-input (PR #196800)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-testing-tools
Author: Joel E. Denny (jdenny-ornl)
Changes
`MarkerRange` makes the computation of marker ranges clearer because it
encapsulates handling of several subtle boundary cases. It will be used more
in a future patch that extends `-dump-input` to present search ranges for all
errors.
This PR is stacked on PR #196799.
---
Full diff: https://github.com/llvm/llvm-project/pull/196800.diff
1 Files Affected:
- (modified) llvm/utils/FileCheck/FileCheck.cpp (+108-39)
``diff
diff --git a/llvm/utils/FileCheck/FileCheck.cpp
b/llvm/utils/FileCheck/FileCheck.cpp
index a33acb926e91f..10f5acf24414c 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -369,10 +369,10 @@ struct InputAnnotation {
/// be different from the starting line of the original diagnostic if
/// !IsFirstLine.
unsigned InputLine;
- /// The column range (one-origin indexing, open end) in which to mark the
- /// input line. If \c InputEndCol is \c UINT_MAX, the rest of the input line
- /// should be marked.
- unsigned InputStartCol, InputEndCol;
+ /// The column range (one-origin indexing, inclusive boundaries) in which to
+ /// mark the input line. If \c InputLastCol is \c UINT_MAX, the rest of the
+ /// input line should be marked.
+ unsigned InputFirstCol, InputLastCol;
/// The marker to use.
MarkerStyle Marker;
/// Whether this annotation represents a good match for an expected pattern.
@@ -472,6 +472,87 @@ class InputAnnotationLabeler {
std::max((std::string::size_type)*LabelWidthGlobal, Label.size());
}
};
+
+/// A range representation with inclusive start and end bounds specifying where
+/// annotation markers are physically drawn in the input dump.
+///
+/// This class encapsulates the conversion of an \c SMRange to lines and
columns
+/// for input annotation markers indicating the same range:
+/// - It handles adjustments to line numbers when a range boundary appears at a
+/// line boundary.
+/// - It avoids related mistakes in determining whether the range is contained
+/// within a single line.
+/// - It avoids the mistake of producing no marker in an input annotation for
an
+/// empty range.
+///
+/// All lines and columns have index-origin one.
+struct MarkerRange {
+public:
+ struct Loc {
+unsigned Line;
+unsigned Col;
+Loc() = default;
+Loc(unsigned Line, unsigned Col) : Line(Line), Col(Col) {}
+Loc(const std::pair &LineAndCol)
+: Line(LineAndCol.first), Col(LineAndCol.second) {}
+ };
+
+private:
+ /// Points to the first character included in the marker range.
+ Loc First;
+ /// Points to the last character included in the marker range.
+ Loc Last;
+ MarkerRange(Loc First, Loc Last) : First(First), Last(Last) {}
+
+public:
+ /// Make an invalid range to be overwritten before being used.
+ MarkerRange() = default;
+ /// Convert \p Range to a \c MarkerRange.
+ ///
+ /// \p Range's start must be inclusive, and its end must be exclusive. It
+ /// specifies the \a logical input range to be depicted by annotation
markers.
+ ///
+ /// The resulting \c MarkerRange's first and last locations are always both
+ /// inclusive. It specifies exactly where markers should be physically
+ /// \a drawn in an input dump. If \p Range is an empty range, then the
+ /// resulting \c MarkerRange is expanded to a single character. This avoids
a
+ /// missing marker for an empty range, but it means the markers for a
+ /// single-character range are indistinguishable from markers for an empty
+ /// range.
+ ///
+ /// Given an \c SMRange representing the range of text "range of text", the
+ /// following example compares how the \c SMRange and a \c MarkerRange
+ /// constructed from it encode their start (s) and end (e) bounds:
+ ///
+ /// foo range of text bar
+ /// seSMRange
+ /// s e MarkerRange
+ ///
+ MarkerRange(const SourceMgr &SM, SMRange Range) {
+First = SM.getLineAndColumn(Range.Start);
+// The SMRange has an exclusive end, but we want an inclusive end.
+if (Range.Start == Range.End) {
+ // Convert the empty range to a one-character range so we do not end up
+ // with a missing marker.
+ Last.Line = First.Line;
+ Last.Col = First.Col;
+} else {
+ // We cannot simply subtract one from the end column number because that
+ // might result in column 0, which does not exist and is thus incorrect
+ // for an inclusive boundary.
+ SMLoc EndLoc = SMLoc::getFromPointer(Range.End.getPointer() - 1);
+ Last = SM.getLineAndColumn(EndLoc);
+}
+ }
+ /// Return true if the marker range is contained on a single line.
+ bool isSingleLine() const { return First.Line == Last.Line; }
+ /// Get the first location included in the marker range.
+ Loc getFirstLoc() const { return First; }
+ /// Get the last location i
[llvm-branch-commits] [llvm] [FileCheck][NFC] Introduce MarkerRange for -dump-input (PR #196800)
https://github.com/jdenny-ornl created
https://github.com/llvm/llvm-project/pull/196800
`MarkerRange` makes the computation of marker ranges clearer because it
encapsulates handling of several subtle boundary cases. It will be used more
in a future patch that extends `-dump-input` to present search ranges for all
errors.
This PR is stacked on PR #196799.
>From 1056b809cc934fab24c24b4466e5097b5664c2c4 Mon Sep 17 00:00:00 2001
From: "Joel E. Denny"
Date: Sat, 9 May 2026 23:35:39 -0400
Subject: [PATCH] [FileCheck][NFC] Introduce MarkerRange for -dump-input
`MarkerRange` makes the computation of marker ranges clearer because
it encapsulates handling of several subtle boundary cases. It will be
used more in a future patch that extends `-dump-input` to present
search ranges for all errors.
---
llvm/utils/FileCheck/FileCheck.cpp | 147 +
1 file changed, 108 insertions(+), 39 deletions(-)
diff --git a/llvm/utils/FileCheck/FileCheck.cpp
b/llvm/utils/FileCheck/FileCheck.cpp
index a33acb926e91f..10f5acf24414c 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -369,10 +369,10 @@ struct InputAnnotation {
/// be different from the starting line of the original diagnostic if
/// !IsFirstLine.
unsigned InputLine;
- /// The column range (one-origin indexing, open end) in which to mark the
- /// input line. If \c InputEndCol is \c UINT_MAX, the rest of the input line
- /// should be marked.
- unsigned InputStartCol, InputEndCol;
+ /// The column range (one-origin indexing, inclusive boundaries) in which to
+ /// mark the input line. If \c InputLastCol is \c UINT_MAX, the rest of the
+ /// input line should be marked.
+ unsigned InputFirstCol, InputLastCol;
/// The marker to use.
MarkerStyle Marker;
/// Whether this annotation represents a good match for an expected pattern.
@@ -472,6 +472,87 @@ class InputAnnotationLabeler {
std::max((std::string::size_type)*LabelWidthGlobal, Label.size());
}
};
+
+/// A range representation with inclusive start and end bounds specifying where
+/// annotation markers are physically drawn in the input dump.
+///
+/// This class encapsulates the conversion of an \c SMRange to lines and
columns
+/// for input annotation markers indicating the same range:
+/// - It handles adjustments to line numbers when a range boundary appears at a
+/// line boundary.
+/// - It avoids related mistakes in determining whether the range is contained
+/// within a single line.
+/// - It avoids the mistake of producing no marker in an input annotation for
an
+/// empty range.
+///
+/// All lines and columns have index-origin one.
+struct MarkerRange {
+public:
+ struct Loc {
+unsigned Line;
+unsigned Col;
+Loc() = default;
+Loc(unsigned Line, unsigned Col) : Line(Line), Col(Col) {}
+Loc(const std::pair &LineAndCol)
+: Line(LineAndCol.first), Col(LineAndCol.second) {}
+ };
+
+private:
+ /// Points to the first character included in the marker range.
+ Loc First;
+ /// Points to the last character included in the marker range.
+ Loc Last;
+ MarkerRange(Loc First, Loc Last) : First(First), Last(Last) {}
+
+public:
+ /// Make an invalid range to be overwritten before being used.
+ MarkerRange() = default;
+ /// Convert \p Range to a \c MarkerRange.
+ ///
+ /// \p Range's start must be inclusive, and its end must be exclusive. It
+ /// specifies the \a logical input range to be depicted by annotation
markers.
+ ///
+ /// The resulting \c MarkerRange's first and last locations are always both
+ /// inclusive. It specifies exactly where markers should be physically
+ /// \a drawn in an input dump. If \p Range is an empty range, then the
+ /// resulting \c MarkerRange is expanded to a single character. This avoids
a
+ /// missing marker for an empty range, but it means the markers for a
+ /// single-character range are indistinguishable from markers for an empty
+ /// range.
+ ///
+ /// Given an \c SMRange representing the range of text "range of text", the
+ /// following example compares how the \c SMRange and a \c MarkerRange
+ /// constructed from it encode their start (s) and end (e) bounds:
+ ///
+ /// foo range of text bar
+ /// seSMRange
+ /// s e MarkerRange
+ ///
+ MarkerRange(const SourceMgr &SM, SMRange Range) {
+First = SM.getLineAndColumn(Range.Start);
+// The SMRange has an exclusive end, but we want an inclusive end.
+if (Range.Start == Range.End) {
+ // Convert the empty range to a one-character range so we do not end up
+ // with a missing marker.
+ Last.Line = First.Line;
+ Last.Col = First.Col;
+} else {
+ // We cannot simply subtract one from the end column number because that
+ // might result in column 0, which does not exist and is thus incorrect
+ // for an inclusive boundary.
+ SMLoc EndLoc = SMLo
