[FileCheck] Move -dump-input diagnostic to first line

Without this patch, `-dump-input` prints a diagnostic at the end of
its marker range.  For example:

```
         1: Start.
check:1     ^~~~~~
         2: Bad.
next:2      X~~~
         3: Many lines
next:2      ~~~~~~~~~~
         4: of input.
next:2      ~~~~~~~~~
         5: End.
next:2      ~~~~ error: no match found
```

This patch moves it to the beginning like this:

```
         1: Start.
check:1     ^~~~~~
         2: Bad.
next:2      X~~~ error: no match found
         3: Many lines
next:2      ~~~~~~~~~~
         4: of input.
next:2      ~~~~~~~~~
         5: End.
next:2      ~~~~
```

The former somehow looks nicer because the diagnostic doesn't appear
to be somewhere within the marker range.  However, the latter is more
practical, especially when the marker range includes the remainder of
a very long dump.  First, in the case of an error, this patch enables
me to search the dump for `error:` and usually immediately land where
the detected error began.  Second, when trying to follow FileCheck's
logic, it's best to read top down, so this patch enables me to see
each diagnostic as soon as I encounter its marker.

Reviewed By: thopre

Differential Revision: https://reviews.llvm.org/D65702

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368786 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Joel E. Denny 2019-08-14 02:56:09 +00:00
parent fb900f7155
commit 7df8868628
2 changed files with 14 additions and 18 deletions

View File

@ -27,13 +27,13 @@
; ALIGN-NEXT:<<<<<<
; ALIGN-NEXT: 1: hello world
; ALIGN-NEXT:check:1 ^~~~~
; ALIGN-NEXT:check:2'0 X~~~~
; ALIGN-NEXT:check:2'0 X~~~~ error: no match found
; ALIGN-NEXT: 2: goodbye
; ALIGN-NEXT:check:2'0 ~~~~~~~
; ALIGN-NEXT: 3: world
; ALIGN-NEXT:check:2'0 ~~~~~
; ALIGN-NEXT: 4: unicorn
; ALIGN-NEXT:check:2'0 ~~~~~~~ error: no match found
; ALIGN-NEXT:check:2'0 ~~~~~~~
; ALIGN-NEXT:check:2'1 ? possible intended match
; ALIGN-NEXT:>>>>>>
; ALIGN-NOT:{{.}}
@ -69,9 +69,9 @@
; CHK-NEXT: 1: hello
; CHK-V-NEXT: check:1 ^~~~~
; CHK-NEXT: 2: again
; CHK-NEXT: check:2'0 X~~~~
; CHK-NEXT: check:2'0 X~~~~ error: no match found
; CHK-NEXT: 3: whirled
; CHK-NEXT: check:2'0 ~~~~~~~ error: no match found
; CHK-NEXT: check:2'0 ~~~~~~~
; CHK-NEXT: check:2'1 ? possible intended match
; CHK-NEXT: >>>>>>
; CHK-NOT: {{.}}
@ -260,9 +260,9 @@
; EMP-NEXT: 2:
; EMP-V-NEXT: empty:2 ^
; EMP-NEXT: 3: world
; EMP-NEXT: empty:3 X~~~~
; EMP-NEXT: empty:3 X~~~~ error: no match found
; EMP-NEXT: 4: label
; EMP-NEXT: empty:3 ~~~~~ error: no match found
; EMP-NEXT: empty:3 ~~~~~
; EMP-V-NEXT: label:4 ^~~~~
; EMP-NEXT: >>>>>>
; EMP-NOT: {{.}}
@ -453,11 +453,11 @@
; LAB-V-NEXT: label:1'0 ^~~~
; LAB-V-NEXT: label:1'1 ^~~~
; LAB-NEXT: 2: foo
; LAB-NEXT: label:3'0 X~~
; LAB-NEXT: label:3'0 X~~ error: no match found
; LAB-NEXT: 3: lab1
; LAB-NEXT: label:3'0 ~~~~
; LAB-NEXT: label:3'1 ? possible intended match
; LAB-NEXT: 4: bar
; LAB-NEXT: label:3'0 ~~~ error: no match found
; LAB-NEXT: label:3'0 ~~~
; LAB-NEXT: >>>>>>
; LAB-NOT: {{.}}

View File

@ -313,8 +313,7 @@ static void BuildInputAnnotations(const std::vector<FileCheckDiag> &Diags,
Label.flush();
LabelWidth = std::max((std::string::size_type)LabelWidth, A.Label.size());
MarkerStyle Marker = GetMarker(DiagItr->MatchTy);
A.Marker = Marker;
A.Marker = GetMarker(DiagItr->MatchTy);
A.FoundAndExpectedMatch =
DiagItr->MatchTy == FileCheckDiag::MatchFoundAndExpected;
@ -333,28 +332,25 @@ static void BuildInputAnnotations(const std::vector<FileCheckDiag> &Diags,
assert(DiagItr->InputStartLine < DiagItr->InputEndLine &&
"expected input range not to be inverted");
A.InputEndCol = UINT_MAX;
A.Marker.Note = "";
Annotations.push_back(A);
for (unsigned L = DiagItr->InputStartLine + 1, E = DiagItr->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 (DiagItr->InputEndCol == 1 && L == E) {
Annotations.back().Marker.Note = Marker.Note;
if (DiagItr->InputEndCol == 1 && L == E)
break;
}
InputAnnotation B;
B.CheckLine = A.CheckLine;
B.CheckDiagIndex = A.CheckDiagIndex;
B.Label = A.Label;
B.InputLine = L;
B.Marker = Marker;
B.Marker = A.Marker;
B.Marker.Lead = '~';
B.Marker.Note = "";
B.InputStartCol = 1;
if (L != E) {
if (L != E)
B.InputEndCol = UINT_MAX;
B.Marker.Note = "";
} else
else
B.InputEndCol = DiagItr->InputEndCol;
B.FoundAndExpectedMatch = A.FoundAndExpectedMatch;
Annotations.push_back(B);