aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny.ornl@gmail.com>2020-07-28 18:09:05 -0400
committerJoel E. Denny <jdenny.ornl@gmail.com>2020-07-28 19:15:18 -0400
commitd680711b94e94e9387076a0daf2a329e304e6751 (patch)
tree5935efba27b72116c3a4e694ca27e54c79a26255 /llvm/utils/FileCheck/FileCheck.cpp
parent2cb926a447d22166dac0d6e6dceaf5b3616ef6a1 (diff)
downloadllvm-d680711b94e94e9387076a0daf2a329e304e6751.zip
llvm-d680711b94e94e9387076a0daf2a329e304e6751.tar.gz
llvm-d680711b94e94e9387076a0daf2a329e304e6751.tar.bz2
[FileCheck] Extend -dump-input with substitutions
Substitutions are already reported in the diagnostics appearing before the input dump in the case of failed directives, and they're reported in traces (produced by `-vv -dump-input=never`) in the case of successful directives. However, those reports are not always convenient to view while investigating the input dump, so this patch adds the substitution report to the input dump too. For example: ``` $ cat check CHECK: hello [[WHAT:[a-z]+]] CHECK: [[VERB]] [[WHAT]] $ FileCheck -vv -DVERB=goodbye check < input |& tail -8 <<<<<< 1: hello world check:1 ^~~~~~~~~~~ 2: goodbye word check:2'0 X~~~~~~~~~~~ error: no match found check:2'1 with "VERB" equal to "goodbye" check:2'2 with "WHAT" equal to "world" >>>>>> ``` Without this patch, the location reported for a substitution for a directive match is the directive's full match range. This location is misleading as it implies the substitution itself matches that range. This patch changes the reported location to just the match range start to suggest the substitution is known at the start of the match. (As in the above example, input dumps don't mark any range for substitutions. The location info in that case simply identifies the right line for the annotation.) Reviewed By: mehdi_amini, thopre Differential Revision: https://reviews.llvm.org/D83650
Diffstat (limited to 'llvm/utils/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/utils/FileCheck/FileCheck.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index fa79c5e..81889b2 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -402,6 +402,18 @@ BuildInputAnnotations(const SourceMgr &SM, unsigned CheckFileBufferID,
LabelWidth = std::max((std::string::size_type)LabelWidth, A.Label.size());
A.Marker = GetMarker(DiagItr->MatchTy);
+ if (!DiagItr->Note.empty()) {
+ A.Marker.Note = DiagItr->Note;
+ // It's less confusing if notes that don't actually have ranges don't have
+ // markers. For example, a marker for 'with "VAR" equal to "5"' would
+ // seem to indicate where "VAR" matches, but the location we actually have
+ // for the marker simply points to the start of the match/search range for
+ // the full pattern of which the substitution is potentially just one
+ // component.
+ if (DiagItr->InputStartLine == DiagItr->InputEndLine &&
+ DiagItr->InputStartCol == DiagItr->InputEndCol)
+ A.Marker.Lead = ' ';
+ }
A.FoundAndExpectedMatch =
DiagItr->MatchTy == FileCheckDiag::MatchFoundAndExpected;