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

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 19:56:09 PDT 2019


Author: jdenny
Date: Tue Aug 13 19:56:09 2019
New Revision: 368786

URL: http://llvm.org/viewvc/llvm-project?rev=368786&view=rev
Log:
[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

Modified:
    llvm/trunk/test/FileCheck/dump-input-annotations.txt
    llvm/trunk/utils/FileCheck/FileCheck.cpp

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=368786&r1=368785&r2=368786&view=diff
==============================================================================
--- llvm/trunk/test/FileCheck/dump-input-annotations.txt (original)
+++ llvm/trunk/test/FileCheck/dump-input-annotations.txt Tue Aug 13 19:56:09 2019
@@ -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:     {{.}}

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=368786&r1=368785&r2=368786&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Tue Aug 13 19:56:09 2019
@@ -313,8 +313,7 @@ static void BuildInputAnnotations(const
     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
       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);




More information about the llvm-commits mailing list