Files
clang-p2996/llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt
Joel E. Denny dd59c1324d [FileCheck] Fix numeric error propagation
A more general name might be match-time error propagation.  That is,
it's conceivable we'll one day have non-numeric errors that require
the handling fixed by this patch.

Without this patch, FileCheck behaves as follows:

```
$ cat check
CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]]

$ FileCheck -vv -dump-input=never check < input
check:1:54: remark: implicit EOF: expected string found in input
CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]]
                                                     ^
<stdin>:2:1: note: found here

^
check:1:15: error: unable to substitute variable or numeric expression: overflow error
CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]]
              ^
$ echo $?
0
```

Notice that the exit status is 0 even though there's an error.
Moreover, FileCheck doesn't print the error diagnostic unless both
`-dump-input=never` and `-vv` are specified.

The same problem occurs when `CHECK-NOT` does have a match but a
capture fails due to overflow: exit status is 0, and no diagnostic is
printed unless both `-dump-input=never` and `-vv` are specified.  The
usefulness of capturing from `CHECK-NOT` is questionable, but this
case should certainly produce an error.

With this patch, FileCheck always includes the error diagnostic and
has non-zero exit status for the above examples.  It's conceivable
that this change will cause some existing tests to fail, but my
assumption is that they should fail.  Moreover, with nearly every
project enabled, this patch didn't produce additional `check-all`
failures for me.

This patch also extends input dumps to include such numeric error
diagnostics for both expected and excluded patterns.

As noted in fixmes in some of the tests added by this patch, this
patch worsens an existing issue with redundant diagnostics.  I'll fix
that bug in a subsequent patch.

Reviewed By: thopre, jhenderson

Differential Revision: https://reviews.llvm.org/D98086
2021-03-17 19:25:41 -04:00

89 lines
3.6 KiB
Plaintext

; Check handling of diagnostics for problematic matches (e.g., variable capture
; overflow) in the case of excluded patterns (e.g., CHECK-NOT).
;
; At one time, FileCheck's exit status for the following example was zero even
; though the excluded pattern does match (it's just capturing that fails).
; Moreover, it printed the error diagnostic only if -vv was specified and input
; dumps were disabled. Test every combination as the logic is hard to get
; right.
;
; TODO: Capturing from an excluded pattern probably shouldn't be permitted
; because it seems useless: it's captured only if the pattern matches, but then
; FileCheck fails. The helpfulness of reporting overflow from that capture is
; perhaps questionable then, but it doesn't seem harmful either. Anyway, the
; goal of this test is simply to exercise the error propagation mechanism for a
; matched excluded pattern. In the future, if we have a more interesting error
; to exercise in that case, we should instead use it in this test, and then we
; might want to think more about where that error should be presented in the
; list of diagnostics.
RUN: echo > %t.chk 'CHECK-NOT: [[#122+1]] [[STR:abc]] [[#NUM:]]'
RUN: echo > %t.in '123 abc 1000000000000000000000000000000000000000000000000000'
ERR-NOT:{{.}}
ERR-VV:{{.*}}: remark: implicit EOF: expected string found in input
ERR-VV-NEXT:CHECK-NOT: {{.*}}
ERR-VV-NEXT:{{ *}}^
ERR-VV-NEXT:{{.*}}: note: found here
ERR-VV-EMPTY:
ERR-VV-NEXT:^
ERR-NOT:{{.}}
ERR:{{.*}}: error: CHECK-NOT: excluded string found in input
ERR-NEXT:CHECK-NOT: {{.*}}
ERR-NEXT:{{ *}}^
ERR-NEXT:<stdin>:1:1: note: found here
ERR-NEXT:123 abc 10{{0*}}
ERR-NEXT:^~~~~~~~~{{~*}}
ERR-NEXT:<stdin>:1:1: note: with "122+1" equal to "123"
ERR-NEXT:123 abc 10{{0*}}
ERR-NEXT:^
ERR-NEXT:<stdin>:1:5: note: captured var "STR"
ERR-NEXT:123 abc 10{{0*}}
ERR-NEXT: ^~~
ERR-NEXT:<stdin>:1:9: error: unable to represent numeric value
ERR-NEXT:123 abc 10{{0*}}
ERR-NEXT: ^
ERR-NOT:{{error|note|remark}}:
DUMP:<<<<<<
DUMP-NEXT: 1: 123 abc 10{{0*}}
DUMP-NEXT:not:1'0 !~~~~~~~~~{{~*}} error: no match expected
DUMP-NEXT:not:1'1 with "122+1" equal to "123"
DUMP-NEXT:not:1'2 !~~ captured var "STR"
DUMP-NEXT:not:1'3 !~{{~*}} error: unable to represent numeric value
DUMP-VV-NEXT: 2:
DUMP-VV-NEXT:eof:1 ^
DUMP-NEXT:>>>>>>
;--------------------------------------------------
; Check -dump-input=never cases.
;--------------------------------------------------
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=never %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=never -v %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=never -vv %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR,ERR-VV
;--------------------------------------------------
; Check -dump-input=fail cases.
;--------------------------------------------------
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=fail %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR,DUMP
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=fail -v %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR,DUMP
RUN: %ProtectFileCheckOutput \
RUN: not FileCheck -dump-input=fail -vv %t.chk < %t.in 2>&1 \
RUN: | FileCheck %s -match-full-lines -check-prefixes=ERR,DUMP,DUMP-VV