[llvm] r349423 - [FileCheck] Annotate input dump (6/7)
Joel E. Denny via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 17 16:03:20 PST 2018
Author: jdenny
Date: Mon Dec 17 16:03:19 2018
New Revision: 349423
URL: http://llvm.org/viewvc/llvm-project?rev=349423&view=rev
Log:
[FileCheck] Annotate input dump (6/7)
This patch implements input annotations for diagnostics reporting
CHECK-DAG discarded matches. These diagnostics are enabled by -vv.
These annotations mark discarded match ranges using `!~~` because they
are bad matches even though they are not errors.
CHECK-DAG discarded matches create another case where there can be
multiple match results for the same directive.
For example:
```
$ FileCheck -dump-input=help
The following description was requested by -dump-input=help to
explain the input annotations printed by -dump-input=always and
-dump-input=fail:
- L: labels line number L of the input file
- T:L labels the only match result for a pattern of type T from line L of
the check file
- T:L'N labels the Nth match result for a pattern of type T from line L of
the check file
- ^~~ marks good match (reported if -v)
- !~~ marks bad match, such as:
- CHECK-NEXT on same line as previous match (error)
- CHECK-NOT found (error)
- CHECK-DAG overlapping match (discarded, reported if -vv)
- X~~ marks search range when no match is found, such as:
- CHECK-NEXT not found (error)
- CHECK-DAG not found after discarded matches (error)
- ? marks fuzzy match when no match is found
- colors success, error, fuzzy match, discarded match, unmatched input
If you are not seeing color above or in input dumps, try: -color
$ FileCheck -vv -dump-input=always check4 < input4 |& sed -n '/^<<<</,$p'
<<<<<<
1: abcdef
dag:1 ^~~~
dag:2'0 !~~~ discard: overlaps earlier match
2: cdefgh
dag:2'1 ^~~~
check:3 X~ error: no match found
>>>>>>
$ cat check4
CHECK-DAG: abcd
CHECK-DAG: cdef
CHECK: efgh
$ cat input4
abcdef
cdefgh
```
This shows that the line 3 CHECK fails to match even though its
pattern appears in the input because its search range starts after the
line 2 CHECK-DAG's match range. The trouble might be that the line 2
CHECK-DAG's match range is later than expected because its first match
range overlaps with the line 1 CHECK-DAG match range and thus is
discarded.
Because `!~~` for CHECK-DAG does not indicate an error, it is not
colored red. Instead, when colors are enabled, it is colored cyan,
which suggests a match that went cold.
Reviewed By: george.karpenkov, probinson
Differential Revision: https://reviews.llvm.org/D53898
Modified:
llvm/trunk/include/llvm/Support/FileCheck.h
llvm/trunk/lib/Support/FileCheck.cpp
llvm/trunk/test/FileCheck/dump-input-annotations.txt
llvm/trunk/utils/FileCheck/FileCheck.cpp
Modified: llvm/trunk/include/llvm/Support/FileCheck.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileCheck.h?rev=349423&r1=349422&r2=349423&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileCheck.h (original)
+++ llvm/trunk/include/llvm/Support/FileCheck.h Mon Dec 17 16:03:19 2018
@@ -160,7 +160,8 @@ struct FileCheckDiag {
/// What kind of match result does this diagnostic describe?
///
/// There might be more than one of these for the same directive. For
- /// example, there might be a fuzzy match after a fail.
+ /// example, there might be several discards before either a final or fail,
+ /// and there might be a fuzzy match after a fail.
enum MatchType {
// TODO: More members will appear with later patches in this series.
/// Indicates the final match for an expected pattern.
@@ -170,6 +171,8 @@ struct FileCheckDiag {
/// Indicates the final match for an expected pattern, but the match is on
/// the wrong line.
MatchFinalButWrongLine,
+ /// Indicates a discarded match for an expected pattern.
+ MatchDiscard,
/// Indicates no match for an expected pattern.
MatchNoneButExpected,
/// Indicates a possible intended match because there's no perfect match.
Modified: llvm/trunk/lib/Support/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileCheck.cpp?rev=349423&r1=349422&r2=349423&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileCheck.cpp (original)
+++ llvm/trunk/lib/Support/FileCheck.cpp Mon Dec 17 16:03:19 2018
@@ -1284,7 +1284,7 @@ FileCheckString::CheckDag(const SourceMg
"match discarded, overlaps earlier DAG match here",
{OldRange});
if (Diags)
- Diags->pop_back();
+ Diags->rbegin()->MatchTy = FileCheckDiag::MatchDiscard;
}
MatchPos = MI->End;
}
Modified: llvm/trunk/test/FileCheck/dump-input-annotations.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/dump-input-annotations.txt?rev=349423&r1=349422&r2=349423&view=diff
==============================================================================
--- llvm/trunk/test/FileCheck/dump-input-annotations.txt (original)
+++ llvm/trunk/test/FileCheck/dump-input-annotations.txt Mon Dec 17 16:03:19 2018
@@ -302,7 +302,7 @@
; NOT2-NOT: {{.}}
;--------------------------------------------------
-; CHECK-DAG (also: matches in different order than directives)
+; CHECK-DAG (also: matches in different order than directives, discarded match)
;--------------------------------------------------
; Good match, discarded match plus good match, and no match.
@@ -319,18 +319,23 @@
; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-Q
; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
-; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-V
+; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-V,DAG-VQ
; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-V,DAG-VV
; DAG: <<<<<<
; DAG-NEXT: 1: abc
; DAG-V-NEXT: dag:2 ^~~
+; DAG-VV-NEXT: dag:3'0 !~~ discard: overlaps earlier match
; DAG-NEXT: 2: def
; DAG-V-NEXT: dag:1 ^~~
+; DAG-VV-NEXT: dag:4'0 !~~ discard: overlaps earlier match
; DAG-NEXT: 3: abc
-; DAG-V-NEXT: dag:3 ^~~
-; DAG-NEXT: dag:4 X~~ error: no match found
+; DAG-VQ-NEXT: dag:3 ^~~
+; DAG-VV-NEXT: dag:3'1 ^~~
+; DAG-Q-NEXT: dag:4 X~~ error: no match found
+; DAG-VQ-NEXT: dag:4 X~~ error: no match found
+; DAG-VV-NEXT: dag:4'1 X~~ error: no match found
; DAG-NEXT: >>>>>>
; DAG-NOT: {{.}}
Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=349423&r1=349422&r2=349423&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Mon Dec 17 16:03:19 2018
@@ -150,6 +150,9 @@ static MarkerStyle GetMarker(FileCheckDi
return MarkerStyle('!', raw_ostream::RED, "error: no match expected");
case FileCheckDiag::MatchFinalButWrongLine:
return MarkerStyle('!', raw_ostream::RED, "error: match on wrong line");
+ case FileCheckDiag::MatchDiscard:
+ return MarkerStyle('!', raw_ostream::CYAN,
+ "discard: overlaps earlier match");
case FileCheckDiag::MatchNoneButExpected:
return MarkerStyle('X', raw_ostream::RED, "error: no match found");
case FileCheckDiag::MatchFuzzy:
@@ -191,10 +194,13 @@ static void DumpInputAnnotationHelp(raw_
OS << " marks bad match, such as:\n"
<< " - CHECK-NEXT on same line as previous match (error)\n"
<< " - CHECK-NOT found (error)\n"
+ << " - CHECK-DAG overlapping match (discarded, reported if "
+ << "-vv)\n"
<< " - ";
WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "X~~";
OS << " marks search range when no match is found, such as:\n"
<< " - CHECK-NEXT not found (error)\n"
+ << " - CHECK-DAG not found after discarded matches (error)\n"
<< " - ";
WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "?";
OS << " marks fuzzy match when no match is found\n";
@@ -207,6 +213,8 @@ static void DumpInputAnnotationHelp(raw_
OS << ", ";
WithColor(OS, raw_ostream::MAGENTA, true) << "fuzzy match";
OS << ", ";
+ WithColor(OS, raw_ostream::CYAN, true, false) << "discarded match";
+ OS << ", ";
WithColor(OS, raw_ostream::CYAN, true, true) << "unmatched input";
OS << "\n\n"
<< "If you are not seeing color above or in input dumps, try: -color\n";
More information about the llvm-commits
mailing list